//
//  ReturnAndChangeViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 15-5-20.
//  Copyright (c) 2015年 RuiBen. All rights reserved.
//

#import "ReturnAndChangeViewController.h"
#import "ReturnAndChangeTableViewCell.h"
#import "ServiceSearchProductTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "GuideListTableViewCell.h"
#import "ResultTableViewCell.h"
#import "GuideListTableViewCell.h"
#import "OldMeterialTableViewCell.h"
#import "HZAreaPickerView.h"
#import <CoreLocation/CoreLocation.h>
#import "EGORefreshTableHeaderView.h"
#import "SearchMemberTableViewCell.h"
#import "FPNumberPadView.h"
#import "OrderDetailTableViewCell.h"
#import "OrderDetailViewController.h"
#import "DepositDetailViewController.h"
#import "CancelOrderOrDepositViewController.h"
#import "PrintWebViewController.h"
#import "CommonScanViewController.h"
#import "FilterViewController.h"
#import "CommonProductDetailViewController.h"
@interface ReturnAndChangeViewController ()<ReturnAndChangeTableViewCellDelegate,HZAreaPickerDelegate,EGORefreshTableHeaderDelegate,FPNumberPadViewDelegate,OrderDetailDelegate,DepositDetailDelegate,CancelOrderOrDepositDelegate,CommonScanDelegate,FilterViewControllerDelegate,CommonProductDetailDelegate>
{
    FilterViewController *filterVC;
    OrderDetailViewController *orderDetailVC;
    DepositDetailViewController *depositDetailVC;
    CancelOrderOrDepositViewController *cancelOrderVC;
    CommonScanViewController *commonScanVC;
    PrintWebViewController *printWebVC;
    CommonProductDetailViewController *commonProductDetailVC;
    EGORefreshTableHeaderView *_refreshHeaderView;
    BOOL _reloading;
    
    NSUInteger _PageIndex;
    NSUInteger _TotalCount;
    NSUInteger _TotalPage;
    NSUInteger _productPageIndex;
    NSUInteger _productTotalCount;
    NSUInteger _productTotalPage;
    
    NSMutableArray *exchangeNumArray;
    NSMutableArray *exchangeNumberArray;
    NSMutableArray *exchangeTypeArray;
    NSMutableArray *exchangeWeightArray;
    NSMutableArray *exchangeStatusArray;
    NSMutableArray *exchangeProductNameArray;
    NSMutableArray *exchangeGuideNameArray;
    NSMutableArray *exchangeMemberNameArray;
    NSMutableArray *exchangePriceArray;
    NSMutableArray *exchangeDateArray;
    NSMutableArray *exchangeReasonArray;
    BOOL statusIsOpen;
    BOOL guideIsOpen;
    
    NSMutableArray *findProductImageArray;
    // NSMutableArray *findProductURLArray;
    NSMutableArray *findProductCodeArray;
    NSMutableArray *findProductNameArray;
    NSMutableArray *findProductPriceArray;
    NSMutableArray *findProductWeightArray;
    NSMutableArray *findProductAddressArray;
    NSMutableArray *findMemberNameArray;
    NSMutableArray *findMemberPhoneArray;
    NSMutableArray *findMemberGradeArray;
    NSMutableArray *findMemberSexArray;
     NSMutableArray *findMemberCodeArray;

    NSMutableArray *findProductDateArray;
    //NSMutableArray *findmProducts;

    NSUInteger searchProductCellTag;
    NSUInteger  searchGuideCellTag;
    NSMutableArray *guideNameArray;
    NSMutableArray *guideCodeArray;
    
    NSString *serviceTypeStr;
    NSString *guideCodeStr;
    
    NSMutableArray *selectedProductImageArray;
    NSMutableArray *selectedProductAddressArray;
    NSMutableArray *selectedProductWeightArray;
    NSMutableArray *selectedProductPriceArray;
    NSMutableArray *selectedProductNameArray;
   // NSMutableArray *selectedStatusArray;
    NSMutableArray *selectedProductCodeArray;

    NSMutableArray *returnDetailUrlArray;
    NSMutableArray *returnDetailProductNameArray;
    NSMutableArray *returnDetailLinePriceArray;
    NSMutableArray *returnDetailWeightArray;
    NSMutableArray *returnAttributesArray;
    NSMutableArray *returnDetailAddressArray;
    NSMutableArray *returnDetailCodeArray;
    
    
    BOOL isOpened;
    
    NSString *memberCodeStr;

   
    NSInteger buShouYinCellTag;
    
    NSString *typeStr;
    
    NSString *openIdStr;
    
    NSString *selectMemberCodeStr;
    
    UITextField *inputTextField;
    
    
    NSInteger exchangeCellTag;
    
    NSMutableArray *filterTypeCodeArray ;
    NSMutableArray *inputFilterCodeArray;
    NSMutableArray *inputMinResultFilterNameArray;
    NSMutableArray *inputMaxResultFilterNameArray;
    NSMutableArray *selectFilterCodeArray;
    NSMutableArray *selectFilterNameArray;
    NSMutableArray *selectCustomTimeArray ;
    NSMutableArray *customTimeFilterTypeCodeArray ;
    NSString *startTimeStr;
    NSString *endTimeStr;

}
- (void)reloadTableViewDataSource;
- (void)doneLoadingTableViewData;
@property (strong, nonatomic) NSString *areaValue, *cityValue;
@property (strong, nonatomic) HZAreaPickerView *locatePicker;
@end

@implementation ReturnAndChangeViewController
@synthesize areaValue=_areaValue, cityValue=_cityValue;
@synthesize locatePicker=_locatePicker;
-(void)viewWillAppear:(BOOL)animated
{
    if ([_isLoad isEqualToString:@"N"]) {
    if (commonProductDetailVC.view!=nil) {
            
            [commonProductDetailVC removeFromParentViewController];
            [commonProductDetailVC.view removeFromSuperview];
            
        }

    if (printWebVC.view!=nil) {
        [printWebVC.view removeFromSuperview];
        [printWebVC removeFromParentViewController];
        
    }
    if (cancelOrderVC.view!=nil) {
        [cancelOrderVC.view removeFromSuperview];
        [cancelOrderVC removeFromParentViewController];
        
    }
    if (orderDetailVC.view!=nil) {
        [orderDetailVC.view removeFromSuperview];
        [orderDetailVC removeFromParentViewController];
        
    }
    if (depositDetailVC.view!=nil) {
        [depositDetailVC.view removeFromSuperview];
        [depositDetailVC removeFromParentViewController];
        
    }
    if (commonScanVC.view!=nil) {
        if (commonScanVC.timer!=nil) {
            [commonScanVC.timer invalidate];
            commonScanVC.timer=nil;
        }
        if (commonScanVC.captureSession!=nil) {
            
            
            [commonScanVC.captureSession stopRunning];
            commonScanVC.captureSession = nil;
        }
        if (commonScanVC.videoPreviewLayer !=nil) {
            
            
            [commonScanVC.videoPreviewLayer removeFromSuperlayer];
        }
        

        [commonScanVC.view removeFromSuperview];
        [commonScanVC removeFromParentViewController];
        
    }
    if (filterVC.view!=nil) {
        
        [filterVC removeFromParentViewController];
        [filterVC.view removeFromSuperview];
        
    }


    [_addExchangeBtn addTarget:self action:@selector(addExchangeButtonClick) forControlEvents:UIControlEventTouchUpInside];
   
    [self initExchange];
    [self initAddExchangeViewContainer];
    [self initExchangeDetailViewContainer];
    [self initOrderFilterView];
    _PageIndex=0;
    [self loadExchangeNextPage:_PageIndex];
    }
}
-(void)initOrderFilterView
{
    inputFilterCodeArray=[NSMutableArray array];
    inputMinResultFilterNameArray=[NSMutableArray array];
    inputMaxResultFilterNameArray=[NSMutableArray array];
    filterTypeCodeArray=[NSMutableArray array];
    customTimeFilterTypeCodeArray=[NSMutableArray array];
    selectFilterCodeArray=[NSMutableArray array];
    selectFilterNameArray=[NSMutableArray array];
    selectCustomTimeArray=[NSMutableArray array];
    
    startTimeStr=@"";
    endTimeStr=@"";
    
    [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f]];
    [_orderFilterImage setImage:[UIImage imageNamed:@"shaixuandingdan_.png"]];
    // [_orderFilterViewContainer bringSubviewToFront:_resetFilterBtn];
    
    _orderFilterBtn.layer.borderColor=[[UIColor colorWithRed:220.0f/255.0f green:220.0f/255.0f blue:220.0f/255.0f alpha:1] CGColor];
    _orderFilterBtn.layer.borderWidth= 1.0f;
    _orderFilterBtn.layer.cornerRadius=4;
    
    [_orderFilterBtn addTarget:self action:@selector(orderFilterBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
}
-(void)orderFilterBtnClick
{
    if (filterVC.view!=nil) {
        
        [filterVC removeFromParentViewController];
        [filterVC.view removeFromSuperview];
        
    }
    filterVC=[[FilterViewController alloc] init];
    filterVC.delegate=self;
    filterVC.docTypeStr=@"Exchange";
    filterVC.selectCustomTimeArray=[NSMutableArray arrayWithArray:selectCustomTimeArray];
    filterVC.startTimeStr=startTimeStr;
    filterVC.endTimeStr=endTimeStr;
    // NSLog(@"selectFilterNameArray=22222======%@",selectFilterNameArray);
    filterVC.selectFilterNameArray=[NSMutableArray arrayWithArray:selectFilterNameArray];
    filterVC.view.frame = CGRectMake(0,
                                     0,
                                     self.view.bounds.size.width,
                                     self.view.bounds.size.height);
    
    [self addChildViewController:filterVC];
    [self.view addSubview:filterVC.view];

}
-(void)confirmFilterBtnClick:(NSMutableArray *)commonFilterTypeCodeArray commonSelectFilterCodeArray:(NSMutableArray *)commonSelectFilterCodeArray commonInputFilterCodeArray:(NSMutableArray *)commonInputFilterCodeArray commonInputMinResultFilterNameArray:(NSMutableArray *)commonInputMinResultFilterNameArray commonInputMaxResultFilterNameArray:(NSMutableArray *)commonInputMaxResultFilterNameArray commonCustomTimeFilterTypeCodeArray:(NSMutableArray *)commonCustomTimeFilterTypeCodeArray commonSelectCustomTimeArray:(NSMutableArray *)commonSelectCustomTimeArray commonSelectFilterNameArray:(NSMutableArray *)commonSelectFilterNameArray  commonStartTimeStr:(NSString *)commonStartTimeStr commonEndTimeStr:(NSString *)commonEndTimeStr isDefault:(NSString *)isDefault
{
    
    if ([isDefault isEqualToString:@"Y"]) {
       
        [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f]];
        [_orderFilterImage setImage:[UIImage imageNamed:@"shaixuandingdan_.png"]];
    }
    else{
        // NSLog(@"_isDefault1111===%@",isDefault);
        [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:203.0f/255.0f green:164.0f/255.0f blue:67.0f/255.0f alpha:1.0f]];
        [_orderFilterImage setImage:[UIImage imageNamed:@"yishaixuan_.png"]];
    }
    
    filterTypeCodeArray=commonFilterTypeCodeArray;
    selectFilterCodeArray=commonSelectFilterCodeArray;
    inputFilterCodeArray=commonInputFilterCodeArray;
    inputMinResultFilterNameArray=commonInputMinResultFilterNameArray;
    inputMaxResultFilterNameArray=commonInputMaxResultFilterNameArray;
    customTimeFilterTypeCodeArray=commonCustomTimeFilterTypeCodeArray;
    selectCustomTimeArray=commonSelectCustomTimeArray;
    selectFilterNameArray=commonSelectFilterNameArray;
    
    startTimeStr=commonStartTimeStr;
    endTimeStr=commonEndTimeStr;
    
    [exchangeNumArray removeAllObjects];
    [exchangeTypeArray removeAllObjects];
    [exchangeWeightArray removeAllObjects];
    [exchangeNumberArray removeAllObjects];
    [exchangeStatusArray removeAllObjects];
    [exchangeProductNameArray removeAllObjects];
    [exchangeGuideNameArray removeAllObjects];
    [exchangeMemberNameArray removeAllObjects];
    [exchangePriceArray removeAllObjects];
    [exchangeDateArray removeAllObjects];
    [ exchangeReasonArray removeAllObjects];
    _PageIndex=0;
    [self loadExchangeNextPage:_PageIndex];

    
}
-(void)initExchange
{
    _searchTextField.text=@"";
    typeStr=@"Exchange1";
    exchangeNumArray=[NSMutableArray array];
    exchangeTypeArray=[NSMutableArray array];
    exchangeWeightArray=[NSMutableArray array];
    exchangeNumberArray=[NSMutableArray array];
    exchangeStatusArray=[NSMutableArray array];
    exchangeProductNameArray=[NSMutableArray array];
    exchangeGuideNameArray=[NSMutableArray array];
    exchangeMemberNameArray=[NSMutableArray array];
    exchangePriceArray=[NSMutableArray array];
    exchangeDateArray=[NSMutableArray array];
    exchangeReasonArray=[NSMutableArray array];
    
}
-(void)initExchangeDetailViewContainer
{
    returnDetailUrlArray=[NSMutableArray array];
    returnDetailProductNameArray=[NSMutableArray array];
    returnDetailLinePriceArray=[NSMutableArray array];
    returnDetailWeightArray=[NSMutableArray array];
    returnAttributesArray=[NSMutableArray array];
    returnDetailAddressArray=[NSMutableArray array];
    returnDetailCodeArray=[NSMutableArray array];
    
    CGRect viewFrame=_exchangeDetailViewContainer.frame;
    viewFrame.origin.y=768;
    _exchangeDetailViewContainer.frame=viewFrame;
    [_exchangeDetailAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_exchangeDetailAlphaView addTarget:self action:@selector(exchangeDetailAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];
    [_relateOrderBtn addTarget:self action:@selector(relateOrderBtnClick) forControlEvents:UIControlEventTouchUpInside];
}
-(void)initAddExchangeViewContainer
{
    [_addRelateOrderBtn addTarget:self action:@selector(addRelateOrderBtnClick) forControlEvents:UIControlEventTouchUpInside];
    _addRelateNoteLabel.hidden=NO;
    _addRelateNumLabel.text=@"";
    selectMemberCodeStr=@"";
    _resultTextView.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
    _resultTextView.layer.borderWidth= 1.0f;
    _resultTextView.layer.cornerRadius=3;
    
    FPNumberPadView *numberPadView1 = [[FPNumberPadView alloc] initWithFrame:CGRectMake(0, 0, 948, 340)];
   // numberPadView1.FPNumberPaddelegate=self;
    numberPadView1.textField = _serviceMoneyTextField;
    [_serviceMoneyTextField addTarget:self action:@selector(updateLabel:)  forControlEvents:UIControlEventEditingDidEnd];
    
    _resultGuideListBtn.tag=60;
    [_resultGuideListBtn addTarget:self action:@selector(selectGuideBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    _searchNoteView.hidden=NO;
    findProductImageArray=[NSMutableArray array];
    // findProductURLArray=[NSMutableArray array];
    findProductCodeArray=[NSMutableArray array];
    findProductNameArray=[NSMutableArray array];
    findProductPriceArray=[NSMutableArray array];
    
    findMemberNameArray=[NSMutableArray array];
    findMemberPhoneArray=[NSMutableArray array];
    findMemberGradeArray=[NSMutableArray array];
    findMemberSexArray=[NSMutableArray array];
    findMemberCodeArray=[NSMutableArray array];
  //  findmProducts=[NSMutableArray array];
    findProductWeightArray=[NSMutableArray array];
     findProductAddressArray=[NSMutableArray array];
    findProductDateArray=[NSMutableArray array];
    
    guideNameArray=[NSMutableArray array];
    guideCodeArray=[NSMutableArray array];
    
    selectedProductImageArray=[NSMutableArray array];
    selectedProductAddressArray=[NSMutableArray array];
    selectedProductWeightArray=[NSMutableArray array];
    selectedProductPriceArray=[NSMutableArray array];
    selectedProductNameArray=[NSMutableArray array];
   // selectedStatusArray=[NSMutableArray array];
    selectedProductCodeArray=[NSMutableArray array];
    
    statusIsOpen=NO;
    guideIsOpen=NO;
    // [_exchangeStatusView setImage:[UIImage imageNamed:@"tangchukuang_.png"]];
    _exchangeStatusViewContainer.hidden=YES;
    CGRect viewFrame=_exchangeStatusViewContainer.frame;
    viewFrame.size.height=1;
    _exchangeStatusViewContainer.frame=viewFrame;
    
//    _changeBtn.hidden=YES;
//    CGRect viewFrame2=_changeBtn.frame;
//    viewFrame2.size.height=1;
//    _changeBtn.frame=viewFrame2;
//    
//    _returnBtn.hidden=YES;
//    CGRect viewFrame3=_returnBtn.frame;
//    viewFrame3.size.height=1;
//    _returnBtn.frame=viewFrame3;
    
    [_addExchangeSearchAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_addExchangeSearchAlphaView addTarget:self action:@selector(addExchangeSearchAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];
    
    [_addExchangeSearchResultAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_addExchangeSearchResultAlphaView addTarget:self action:@selector(addExchangeSearchResultAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];
    
    CGRect viewFrame1=_addExchangeViewContainer.frame;
    viewFrame1.origin.y=768;
    _addExchangeViewContainer.frame=viewFrame1;
    CGRect frame=_addExchangeSearchResultView.frame;
    frame.origin.y=768;
    [_addExchangeSearchResultView setFrame:frame];
    CGRect frame1=_addExchangeSearchView.frame;
    frame1.origin.y=0;
    [_addExchangeSearchView setFrame:frame1];
    
    //[_exchangeStatusBtn addTarget:self action:@selector(exchangeStatusBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    [_qualityProblemButton addTarget:self action:@selector(serviceTypeClick:) forControlEvents:UIControlEventTouchUpInside];
    [_noSuitableButton addTarget:self action:@selector(serviceTypeClick:) forControlEvents:UIControlEventTouchUpInside];
    [_otherButton addTarget:self action:@selector(serviceTypeClick:) forControlEvents:UIControlEventTouchUpInside];
    
}
-(IBAction)printBtnClick:(id)sender
{
    if (printWebVC.view!=nil) {
        [printWebVC.view removeFromSuperview];
        [printWebVC removeFromParentViewController];
        
    }
    printWebVC=[[PrintWebViewController alloc] init];
    //  printWebVC.delegate=self;
    printWebVC.docNumStr=_exchangeNumLabel.text;
    printWebVC.docTypeStr=@"Exchange";
    printWebVC.docStatusStr=@"";
    printWebVC.view.frame = CGRectMake(0,
                                       0,
                                       self.view.bounds.size.width,
                                       self.view.bounds.size.height);
    
    [self addChildViewController:printWebVC];
    [self.view addSubview:printWebVC.view];
    
    
}

-(void)addRelateOrderBtnClick
{
    if (_addRelateNumLabel.text.length>0) {
        
        
        if (orderDetailVC.view!=nil) {
            [orderDetailVC.view removeFromSuperview];
            [orderDetailVC removeFromParentViewController];
            
        }
        orderDetailVC=[[OrderDetailViewController alloc] init];
        orderDetailVC.delegate=self;
        orderDetailVC.docNumStr=_addRelateNumLabel.text;
        // orderDetailVC.isHiddenStr=@"Y";
        orderDetailVC.view.frame = CGRectMake(0,
                                              0,
                                              self.view.bounds.size.width,
                                              self.view.bounds.size.height);
        
        [self addChildViewController:orderDetailVC];
        [self.view addSubview:orderDetailVC.view];
    }
    
    else
    {
        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"未关联订单" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
    }

}
-(void)relateOrderBtnClick
{
    if (_relateNumLabel.text.length>0) {
        
   
    if (orderDetailVC.view!=nil) {
        [orderDetailVC.view removeFromSuperview];
        [orderDetailVC removeFromParentViewController];
        
    }
    orderDetailVC=[[OrderDetailViewController alloc] init];
    orderDetailVC.delegate=self;
    orderDetailVC.docNumStr=_relateNumLabel.text;
   // orderDetailVC.isHiddenStr=@"Y";
    orderDetailVC.view.frame = CGRectMake(0,
                                          0,
                                          self.view.bounds.size.width,
                                          self.view.bounds.size.height);
    
    [self addChildViewController:orderDetailVC];
    [self.view addSubview:orderDetailVC.view];
    }
    
    else
    {
        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"未关联订单" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
    }

}
//orderDetailDelegate
-(void)orderDetailAlphaViewClick
{
    if (orderDetailVC.view!=nil) {
        [orderDetailVC.view removeFromSuperview];
        [orderDetailVC removeFromParentViewController];
        
    }
}
-(void)RelateDepositBtnClick
{
    if (orderDetailVC.relatedDocNumLabel.text.length>0) {
        
    
    if (depositDetailVC.view!=nil) {
        
        [depositDetailVC removeFromParentViewController];
        [depositDetailVC.view removeFromSuperview];
        
    }
    depositDetailVC=[[DepositDetailViewController alloc] init];
    depositDetailVC.delegate=self;
    depositDetailVC.docNumStr=orderDetailVC.relatedDocNumLabel.text;
    
    
    depositDetailVC.view.frame = CGRectMake(0,
                                            0,
                                            self.view.bounds.size.width,
                                            self.view.bounds.size.height);
    
    [self addChildViewController:depositDetailVC];
    [self.view addSubview:depositDetailVC.view];
    }
    else
    {
        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"未关联定金单" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
    }
    
}
-(void)CancelOrderBtnClick
{
    //    if (orderDetailVC.view!=nil) {
    //      //  NSLog(@"rrwrwrwrwrw");
    //        [orderDetailVC removeFromParentViewController];
    //        [orderDetailVC.view removeFromSuperview];
    //
    //    }
    if (cancelOrderVC.view!=nil) {
        
        [cancelOrderVC removeFromParentViewController];
        [cancelOrderVC.view removeFromSuperview];
        
    }
    cancelOrderVC=[[CancelOrderOrDepositViewController alloc] init];
    cancelOrderVC.delegate=self;
    cancelOrderVC.DocNumStr=orderDetailVC.detailNumLabel.text;
    cancelOrderVC.DocTypeStr=@"Order";
    cancelOrderVC.titleStr=@"取消订单";
    
    cancelOrderVC.view.frame = CGRectMake(0,
                                          0,
                                          self.view.bounds.size.width,
                                          self.view.bounds.size.height);
    
    [self addChildViewController:cancelOrderVC];
    [self.view addSubview:cancelOrderVC.view];
    // [self.view bringSubviewToFront:cancelOrderVC.view];
    
}
//DepositDetailDelegate
-(void)DepositDetailAlphaViewClick
{
    if (depositDetailVC.view!=nil) {
        
        [depositDetailVC removeFromParentViewController];
        [depositDetailVC.view removeFromSuperview];
        
    }
    
}
-(void)DepositDetailCanCelDepositClick
{
    if (cancelOrderVC.view!=nil) {
        
        [cancelOrderVC removeFromParentViewController];
        [cancelOrderVC.view removeFromSuperview];
        
    }
    cancelOrderVC=[[CancelOrderOrDepositViewController alloc] init];
    cancelOrderVC.delegate=self;
    cancelOrderVC.DocNumStr=depositDetailVC.detailNumLabel.text;
    cancelOrderVC.DocTypeStr=@"Deposit";
    cancelOrderVC.titleStr=@"取消定金单";
    
//    cancelOrderVC.statusStr1=depositDetailVC.detailStatusLabel.text;
//    cancelOrderVC.statusStr2=depositDetailVC.detailTypeLabel.text;
    
    
    cancelOrderVC.view.frame = CGRectMake(0,
                                          0,
                                          self.view.bounds.size.width,
                                          self.view.bounds.size.height);
    
    [self addChildViewController:cancelOrderVC];
    [self.view addSubview:cancelOrderVC.view];
    
}
-(void)DepositDetailRelateOrderClick
{
    //    if (depositDetailVC.view!=nil) {
    //
    //        [depositDetailVC removeFromParentViewController];
    //        [depositDetailVC.view removeFromSuperview];
    //
    //    }
    if (orderDetailVC.view!=nil) {
        [orderDetailVC.view removeFromSuperview];
        [orderDetailVC removeFromParentViewController];
        
    }
    orderDetailVC=[[OrderDetailViewController alloc] init];
    orderDetailVC.delegate=self;
    orderDetailVC.docNumStr=depositDetailVC.relateOrderNumLabel.text;
    orderDetailVC.view.frame = CGRectMake(0,
                                          0,
                                          self.view.bounds.size.width,
                                          self.view.bounds.size.height);
    
    [self addChildViewController:orderDetailVC];
    [self.view addSubview:orderDetailVC.view];
    
    
    
    
}

-(void)updateLabel:(UITextField *)sender
{
    
       _totalMoneyLabel.text= [NSString stringWithFormat:@"-%@",sender.text];

}

-(void)selectGuideBtnClick:(UIButton *)sender
{
    if (sender.tag==60) {
        
   
           if (guideIsOpen) {
            _resultGuideListViewContainer.hidden=YES;
            [UIView animateWithDuration:0.5 animations:^{
                
//                UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
//                [_resultGuideListArrowImage setImage:closeImage];
                CGRect frame=_resultGuideListViewContainer.frame;
                
                frame.size.height=1;
                [_resultGuideListViewContainer setFrame:frame];
                
            } completion:^(BOOL finished){
                guideIsOpen=NO;
            }];
            
        }
        else
        {
            [self requestGuideList];
            _resultGuideListViewContainer.hidden=NO;
            [UIView animateWithDuration:0.5 animations:^{
//                UIImage *closeImage=[UIImage imageNamed:@"jiantou_upward.png"];
//                
//                
//                [_resultGuideListArrowImage setImage:closeImage];
                CGRect frame=_resultGuideListViewContainer.frame;
                
                frame.size.height=657;
                [_resultGuideListViewContainer setFrame:frame];
                
            } completion:^(BOOL finished){
                guideIsOpen=YES;
            }];
            
        }
    }
    
}
-(void)requestGuideList
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [HttpRequest requestData:@"Guide/GuideList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    [guideCodeArray removeAllObjects];
                    [guideNameArray removeAllObjects];
                  NSMutableArray *mGuidesArray=[severDataDict.dataDict objectForKey:@"DataLine"];
                    for (int i=0; i<mGuidesArray.count; i++) {
                        [guideCodeArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"UserCode"]];
                        [guideNameArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"UserName"]];
                    }
                    // NSLog(@"guideCodeArray==%@",guideCodeArray);
                    //
                  //  [_guideListTableView reloadData];
                    [_resultGuideListTableView reloadData];
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                    [Global loginViewController:self noteStr:requestResultStr];
                     //   [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}
-(void)exchangeDetailAlphaViewClick
{
    [_searchTextField resignFirstResponder];
    [_searchProductTextField resignFirstResponder];
    [_serviceMoneyTextField resignFirstResponder];
    [_resultTextField resignFirstResponder];

    [_remarkTextView resignFirstResponder];
    
    [_resultTextView resignFirstResponder];

   // _exchangeDetailScrollview
     [_exchangeDetailScrollview setContentOffset:CGPointMake(0, 0)];
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_exchangeDetailViewContainer.frame;
         viewFrame.origin.y=768;
         _exchangeDetailViewContainer.frame=viewFrame;
     }completion:^(BOOL finished) {
         
     }];

}
-(void)addExchangeSearchAlphaViewClick
{
    [_searchTextField resignFirstResponder];
    [_searchProductTextField resignFirstResponder];
    [_serviceMoneyTextField resignFirstResponder];
    [_resultTextField resignFirstResponder];
   
    [_remarkTextView resignFirstResponder];
     [_resultTextView resignFirstResponder];
 
    
    CGRect viewFrame=_addExchangeViewContainer.frame;
    viewFrame.origin.y=0;
    _addExchangeViewContainer.frame=viewFrame;
    CGRect viewFrame1=_addExchangeSearchView.frame;
    viewFrame1.origin.y=768;
    _addExchangeSearchView.frame=viewFrame1;
//    [UIView animateWithDuration:0.5f animations:^
//     {
         CGRect viewFrame0=_addExchangeSearchResultView.frame;
         viewFrame0.origin.y=0;
         _addExchangeSearchResultView.frame=viewFrame0;
//     }completion:^(BOOL finished) {
//         
//     }];
    
}
-(void)addExchangeSearchResultAlphaViewClick
{
    [_searchTextField resignFirstResponder];
    [_searchProductTextField resignFirstResponder];
    [_serviceMoneyTextField resignFirstResponder];
    [_resultTextField resignFirstResponder];
    
    [_remarkTextView resignFirstResponder];
    [_resultTextView resignFirstResponder];
    [_resultScrollview setContentOffset:CGPointMake(0, 0)];
   
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_addExchangeViewContainer.frame;
         viewFrame.origin.y=768;
         _addExchangeViewContainer.frame=viewFrame;
         CGRect viewFrame1=_addExchangeSearchView.frame;
         viewFrame1.origin.y=768;
         _addExchangeSearchView.frame=viewFrame1;
         CGRect viewFrame0=_addExchangeSearchResultView.frame;
         viewFrame0.origin.y=768;
         _addExchangeSearchResultView.frame=viewFrame0;
     }completion:^(BOOL finished) {
         
     }];
    
}

-(void)addExchangeButtonClick
{
    [_searchTextField resignFirstResponder];
    for (int i=0; i<3; i++) {
        UIImageView *img=(UIImageView *)[self.view viewWithTag:2000+i];
        [img setImage:[UIImage imageNamed:@"0000.png"]];
        
    }
    _addRelateNoteLabel.hidden=NO;
    
    _addRelateNumLabel.text=@"";
    _resultSexImg.hidden=YES;
     _memberNoteLabel.hidden=NO;
    _resultMemberNameAndPhoneLabel.hidden=YES;
     selectMemberCodeStr=@"";
    _resultGradeTagLabel.hidden=YES;
    _resultGradeLabel.hidden=YES;
    _serviceMoneyTextField
    .text=@"";
    serviceTypeStr=@"";
    _totalMoneyLabel.text=@"";
    guideCodeStr=[Global getGuideCodeStr];
    _resultGuideNameLabel.text=[Global getGuideNameStr];
    [Global resizeForLable:_resultGuideNameLabel WithText:_resultGuideNameLabel.text parentView:self.view];
    CGRect frameK=_resultGuideNameLabel.frame;
    frameK.origin.x=_resultGuideListArrowImage.frame.origin.x-frameK.size.width-5;
    _resultGuideNameLabel.frame=frameK;
    
    _searchNoteView.hidden=NO;
    _resultNoteView.hidden=NO;
    _searchProductTextField.text=@"";
    _searchTotalLabel.text=@"共有0个结果";
    _resultTextView.text=@"";
    _resultTextViewImage.hidden=NO;
    _resultTextViewLabel.hidden=NO;
   // _resultGuideNameLabel.text=[Global getGuideNameStr];
   // guideCodeStr=[Global getGuideCodeStr];
    [findProductImageArray removeAllObjects];
    [findProductCodeArray removeAllObjects];
    [findProductNameArray removeAllObjects];
    [findProductPriceArray removeAllObjects];
    [findProductWeightArray removeAllObjects];
    [findProductAddressArray removeAllObjects];
    [findMemberNameArray removeAllObjects];
    [findMemberPhoneArray removeAllObjects];
    [findMemberGradeArray removeAllObjects];
    [findMemberSexArray removeAllObjects];
    [findMemberCodeArray removeAllObjects];
    //  [findProductAddressArray  addObject:[[findmProducts objectAtIndex:i] objectForKey:@"ItemName"]];
    
    [findProductDateArray  removeAllObjects];
    [_searchProductTableView reloadData];
    
    
    [selectedProductImageArray removeAllObjects];
    [selectedProductAddressArray removeAllObjects];
    [selectedProductWeightArray removeAllObjects];
    [selectedProductPriceArray removeAllObjects];
    [selectedProductNameArray removeAllObjects];
    //[selectedStatusArray removeAllObjects];
    [selectedProductCodeArray removeAllObjects];
    [_resultTableView reloadData];

    CGRect frame3=_resultTableView.frame;
    frame3.size.height=120;
    _resultTableView.frame=frame3;
    
    CGRect frame2=_resultView.frame;
    frame2.origin.y=289;
    _resultView.frame=frame2;
    
    [guideCodeArray removeAllObjects];
    [guideNameArray removeAllObjects];
    [_resultGuideListTableView reloadData];
    
    _resultGuideListViewContainer.hidden=YES;
       CGRect frame=_resultGuideListViewContainer.frame;
    frame.size.height=1;
    [_resultGuideListViewContainer setFrame:frame];
   
    guideIsOpen=NO;
    
    [_resultScrollview setContentSize:CGSizeMake(0, _resultView.frame.origin.y+ _resultView.frame.size.height+50)];
    [_resultScrollview setScrollEnabled:YES];


    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_addExchangeViewContainer.frame;
         viewFrame.origin.y=0;
         _addExchangeViewContainer.frame=viewFrame;
     }completion:^(BOOL finished) {
         
     }];
    
    CGRect framea=_addExchangeSearchView.frame;
    
    framea.origin.y=768;
    [_addExchangeSearchView setFrame:framea];
    
//        UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
//        [_resultGuideListArrowImage setImage:closeImage];
    
        CGRect frame1=_addExchangeSearchResultView.frame;
        
        frame1.origin.y=0;
        [_addExchangeSearchResultView setFrame:frame1];
        
    

}
-(void) loadExchangeNextPage:(NSUInteger)oldPageNum {
    if(oldPageNum!=0 && _TotalCount<=exchangeNumArray.count)
        return;
    if(oldPageNum == 0){
        [exchangeNumArray removeAllObjects];
        [_exchangeTableView reloadData];
    }
    _PageIndex=oldPageNum+1;
    [self requestExchangeList: _PageIndex pageSize:7];
}
-(void)requestExchangeList:(NSUInteger)pageIndex pageSize:(NSUInteger)pageSize
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:pageSize];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:pageIndex];
        //        NSString *pageSizeStr=[NSString stringWithFormat:@"%d",pageSize];
        //        NSString *pageIndexStr=[NSString stringWithFormat:@"%d",pageIndex];
        
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
        [params setObject:_searchTextField.text forKey:@"KeyWord"];
        NSMutableArray *mDocumentLine=[NSMutableArray array];
        for (int i=0; i<filterTypeCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            //    NSLog(@"codeContentssss==%@",codeContent);
            [dic setValue:[filterTypeCodeArray objectAtIndex:i] forKey:@"FilterTypeCode"];
            //  NSLog(@"countContentssss==%@",countContent);
            [dic setValue:[selectFilterCodeArray objectAtIndex:i] forKey:@"FilterCode"];
            [mDocumentLine addObject:dic];
            
        }
        NSMutableArray *mDocumentLine1=[NSMutableArray array];
        for (int i=0; i<customTimeFilterTypeCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            //    NSLog(@"codeContentssss==%@",codeContent);
            [dic setValue:[customTimeFilterTypeCodeArray objectAtIndex:i] forKey:@"FilterTypeCode"];
            //  NSLog(@"countContentssss==%@",countContent);
            [dic setValue:startTimeStr forKey:@"Value1"];
            [dic setValue:endTimeStr forKey:@"Value2"];
            [mDocumentLine1 addObject:dic];
            
        }

        [params setObject:mDocumentLine forKey:@"DataLineFileterParam"];
        [params setObject:mDocumentLine1 forKey:@"DataLineFileterParam2"];
        // NSLog(@"paramsLIST====%@",params);
        [HttpRequest requestData:@"Guide/ExchangeList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                   // _searchNoteView.hidden=YES;
                  //  NSLog(@"serviceeeee====%@",severDataDict.dataDict);
                    _TotalCount=[[severDataDict.dataDict objectForKey:@"TotalCount"] integerValue];
                    NSInteger numberInteger=[[severDataDict.dataDict objectForKey:@"DocQCount"] integerValue];
                    float gramInteger=[[severDataDict.dataDict objectForKey:@"DocGramTotal"] floatValue];
                    float priceInteger=[[severDataDict.dataDict objectForKey:@"DocPriceTotal"] floatValue];
                    _totalExchangeLabel.text=[NSString stringWithFormat:@"共有%lu个记录  %ld件/%@g   ¥%@",(unsigned long)_TotalCount,(long)numberInteger,[Global floatConvertPercentile:gramInteger],[Global floatConvertPercentile:priceInteger]];
                   // _totalExchangeLabel.text=[NSString stringWithFormat:@"共有%lu个记录",(unsigned long)_TotalCount];
                    if (_TotalCount%7!=0) {
                        _TotalPage=_TotalCount/7+1;
                    }
                    else if (_TotalCount%7==0)
                    {
                        _TotalPage=_TotalCount/7;
                    }
                    

                    NSMutableArray *mExchangeArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    
                    //     NSLog(@"mOrderArray===%@",mOrderArray);
                    if ( mExchangeArray.count>0) {
                        for (int i=0; i< mExchangeArray.count; i++) {
                            
                            [exchangeNumArray addObject:[[mExchangeArray objectAtIndex:i] objectForKey:@"DocNum"]];
                            [exchangeTypeArray addObject:[[mExchangeArray objectAtIndex:i] objectForKey:@"DocType"]];
                            [exchangeWeightArray addObject:[[mExchangeArray objectAtIndex:i] objectForKey:@"GramTotalD"]];
                            [exchangeNumberArray addObject:[[mExchangeArray objectAtIndex:i] objectForKey:@"NumberD"]];
                            [exchangeStatusArray addObject:[[mExchangeArray objectAtIndex:i] objectForKey:@"DocStatus"]];
                            [exchangeProductNameArray addObject:[[mExchangeArray objectAtIndex:i] objectForKey:@"ItemNameD"]];
                            [exchangeGuideNameArray addObject:[[mExchangeArray objectAtIndex:i] objectForKey:@"GuideName"]];
                            [exchangeMemberNameArray addObject:[[mExchangeArray objectAtIndex:i] objectForKey:@"MemberName"]];
                            [exchangePriceArray addObject:[[mExchangeArray objectAtIndex:i] objectForKey:@"DocTotal"]];
                            [exchangeDateArray addObject:[[mExchangeArray objectAtIndex:i] objectForKey:@"DocDate"]];
                            [ exchangeReasonArray addObject:[[mExchangeArray objectAtIndex:i] objectForKey:@"Reasons"]];
                        }
                    }
                    
                    [_exchangeTableView reloadData];
                    
                   
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                    [Global loginViewController:self noteStr:requestResultStr];
                    //    [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    if (_refreshHeaderView == nil) {
        EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - _exchangeTableView.bounds.size.height, self.view.frame.size.width, _exchangeTableView.bounds.size.height)];
        view.delegate = self;
        [_exchangeTableView addSubview:view];
        _refreshHeaderView = view;
        
        
    }
    
    //  update the last update date
    [_refreshHeaderView refreshLastUpdatedDate];
    // Do any additional setup after loading the view from its nib.
}
#pragma mark -
#pragma mark Data Source Loading / Reloading Methods

- (void)reloadTableViewDataSource{
    
    [exchangeNumArray removeAllObjects];
    [exchangeTypeArray removeAllObjects];
    [exchangeWeightArray removeAllObjects];
    [exchangeNumberArray removeAllObjects];
    [exchangeStatusArray removeAllObjects];
    [exchangeProductNameArray removeAllObjects];
    [exchangeGuideNameArray removeAllObjects];
    [exchangeMemberNameArray removeAllObjects];
    [exchangePriceArray removeAllObjects];
    [exchangeDateArray removeAllObjects];
    [ exchangeReasonArray removeAllObjects];
    _PageIndex=0;
    [self loadExchangeNextPage:_PageIndex];
    //  should be calling your tableviews data source model to reload
    //  put here just for demo
    _reloading = YES;
    
}

- (void)doneLoadingTableViewData{
    
    //  model should call this when its done loading
    _reloading = NO;
    [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:_exchangeTableView];
    
}


#pragma mark -
#pragma mark UIScrollViewDelegate Methods

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView==_exchangeTableView) {
    [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
    }
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    if (scrollView==_exchangeTableView) {
    [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
    }
}


#pragma mark -
#pragma mark EGORefreshTableHeaderDelegate Methods

- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
    
    [self reloadTableViewDataSource];
    [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];
    
}

- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{
    
    return _reloading; // should return if data source model is reloading
    
}

- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{
    
    return [NSDate date]; // should return date data source was last changed
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
      if (tableView==_exchangeTableView) {
        return exchangeNumArray.count;
    }
    else if (tableView==_searchProductTableView) {
        
        return findProductImageArray.count;
    }
    else if(tableView==_resultGuideListTableView)
    {
        return guideCodeArray.count;
    }
    else if (tableView==_resultTableView)
    {
        return selectedProductCodeArray.count;
    }
        else if (tableView==_returnDetailTableView)
    {
        return returnDetailUrlArray.count;
    }
  
    return 1;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==_exchangeTableView||tableView==_searchProductTableView||tableView==_resultTableView||tableView==_returnDetailTableView) {
        return 120;
    }
    else if(tableView==_resultGuideListTableView)
    
        return 60;
    return 50;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView==_exchangeTableView) {
        static NSString * const  exchangeIdentifier = @"exchangeIdentifier";
        ReturnAndChangeTableViewCell *cell=( ReturnAndChangeTableViewCell *)[tableView dequeueReusableCellWithIdentifier: exchangeIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"ReturnAndChangeTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
            cell.delegate=self;
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame] ;
//        cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:250.0f/255.0f green:250.0f/255.0f blue:250.0f/255.0f alpha:1.0f];
//        cell.piaoJuBuDaButton.tag=indexPath.row;
        cell.buShouYinBtn.tag=indexPath.row;
//        cell.huiYuanBuDengButton.tag=indexPath.row;
        if (exchangeNumArray.count>0) {
            cell.returnNumLabel.text=[exchangeNumArray objectAtIndex:indexPath.row];
           // [self resizeLabel:cell.returnNumLabel];
            [Global resizeForLable:cell.returnNumLabel WithText:cell.returnNumLabel.text parentView:self.view];
            
            CGRect frame=cell.returnStatusLabel.frame;
            frame.origin.x=cell.returnNumLabel.frame.origin.x+cell.returnNumLabel.frame.size.width-37;
            cell.returnStatusLabel.frame=frame;
            
//            CGRect frame1=cell.returnReasonLabel.frame;
//            frame1.origin.x=cell.returnStatusLabel.frame.origin.x+cell.returnStatusLabel.frame.size.width+2;
//            cell.returnReasonLabel.frame=frame1;
        }
        if (exchangeMemberNameArray.count>0) {
            cell.memberNameLabel.text=[NSString stringWithFormat:@"%@",[exchangeMemberNameArray objectAtIndex:indexPath.row]];
        }
        if (exchangeStatusArray.count>0) {
            cell.returnStatusLabel.text=[NSString stringWithFormat:@"【%@】",[exchangeStatusArray objectAtIndex:indexPath.row]];
        
        if ([[exchangeStatusArray objectAtIndex:indexPath.row] isEqualToString:@"已结算"]) {
          //  cell.returnStatusLabel.layer.borderColor=[[UIColor colorWithRed:144.0f/255.0f green:185.0f/255.0f blue:109.0f/255.0f alpha:1] CGColor];
            //  [cell.confirmArrivalBtn.];
            
            [cell.returnStatusLabel setTextColor:[Global parseStatusColor:[exchangeStatusArray objectAtIndex:indexPath.row]]];
            //[cell.confirmArrivalBtn setTintColor:];
           
        }
        else
        {
             [cell.returnStatusLabel setTextColor:[Global parseStatusColor:[exchangeStatusArray objectAtIndex:indexPath.row]]];
          //  [cell.returnStatusLabel setUserInteractionEnabled:YES];
            
            
        }
        }


        if (exchangeGuideNameArray.count>0) {
            cell.guideNameLabel.text=[exchangeGuideNameArray objectAtIndex:indexPath.row];
           // [self resizeLabel:cell.guideNameLabel];
             [Global resizeForLable:cell.guideNameLabel WithText:cell.guideNameLabel.text parentView:self.view];
            CGRect frame=cell.memberNameTagLabel.frame;
            frame.origin.x=cell.guideNameLabel.frame.origin.x+cell.guideNameLabel.frame.size.width+15;
            cell.memberNameTagLabel.frame=frame;

        }
        if (exchangeMemberNameArray.count>0) {
            NSString *memberNameStr=[exchangeMemberNameArray objectAtIndex:indexPath.row];
            if (memberNameStr.length>0) {
                cell.memberNameLabel.text=memberNameStr;
            }
            else
            {
            cell.memberNameLabel.text=@"未填写";
            }
           // [self resizeLabel:cell.memberNameLabel];
            [Global resizeForLable:cell.memberNameLabel WithText:cell.memberNameLabel.text parentView:self.view];
            CGRect frame=cell.memberNameLabel.frame;
            frame.origin.x=cell.memberNameTagLabel.frame.origin.x+cell.memberNameTagLabel.frame.size.width+2;
            cell.memberNameLabel.frame=frame;
            
            CGRect frame1=cell.dateTagLabel.frame;
            frame1.origin.x=cell.memberNameLabel.frame.origin.x+cell.memberNameLabel.frame.size.width+15;
            cell.dateTagLabel.frame=frame1;
            
            CGRect frame2=cell.dateLabel.frame;
            frame2.origin.x=cell.dateTagLabel.frame.origin.x+cell.dateTagLabel.frame.size.width+2;
            cell.dateLabel.frame=frame2;


        }
        if (exchangeDateArray.count>0) {
            cell.dateLabel.text=[exchangeDateArray objectAtIndex:indexPath.row];
        }
        
        NSString *numberStr=@"";
        NSString *weightStr=@"";
        NSString *nameStr=@"";
        if (exchangeNumberArray.count>0) {
            numberStr=[NSString stringWithFormat:@"%ld",(long)[[exchangeNumberArray objectAtIndex:indexPath.row] integerValue]];
        }
        if (exchangeWeightArray.count>0) {
            weightStr=[NSString stringWithFormat:@"%0.02f",[[exchangeWeightArray objectAtIndex:indexPath.row] floatValue]];
        }

        if (exchangeProductNameArray.count>0) {
             nameStr=[exchangeProductNameArray objectAtIndex:indexPath.row];
            if ([numberStr floatValue]>1) {
                cell.returnProductNameLabel.text=[NSString stringWithFormat:@"%@...  共%@件/%@g",nameStr,numberStr,weightStr];
            }
            else
            {
                cell.returnProductNameLabel.text=[NSString stringWithFormat:@"%@  共%@件/%@g",nameStr,numberStr,weightStr];
            }

           // cell.returnProductNameLabel.text=[exchangeProductNameArray objectAtIndex:indexPath.row];
           // [self resizeLabel:cell.returnProductNameLabel];
             [Global resizeForLable:cell.returnProductNameLabel WithText:cell.returnProductNameLabel.text parentView:self.view];
            CGRect frame=cell.returnPriceTagLabel.frame;
            frame.origin.x=cell.returnProductNameLabel.frame.origin.x+cell.returnProductNameLabel.frame.size.width+15;
            cell.returnPriceTagLabel.frame=frame;
            
            CGRect frame1=cell.returnPriceLabel.frame;
            frame1.origin.x=cell.returnPriceTagLabel.frame.origin.x+cell.returnPriceTagLabel.frame.size.width+2;
            cell.returnPriceLabel.frame=frame1;

        }
       
        if (exchangePriceArray.count>0) {
            float AvgPrice1=[[exchangePriceArray objectAtIndex:indexPath.row] floatValue];
            NSString *AvgPriceStr1=[Global floatConvertPercentile:AvgPrice1];
            cell.returnPriceLabel.text=[NSString stringWithFormat:@"¥%@",AvgPriceStr1];
            if ([[exchangePriceArray objectAtIndex:indexPath.row] floatValue]<=0||[[exchangeStatusArray objectAtIndex:indexPath.row] isEqualToString:@"已结算"]) {
                cell.buShouYinBtn.layer.borderColor=[[UIColor colorWithRed:245.0f/255.0f green:245.0f/255.0f blue:245.0f/255.0f alpha:1] CGColor];
                //  [cell.confirmArrivalBtn.];
                [cell.buShouYinBtn setTitleColor:[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                //[cell.confirmArrivalBtn setTintColor:];
                [cell.buShouYinBtn setUserInteractionEnabled:NO];
            }
            else
            {
                cell.buShouYinBtn.layer.borderColor=[[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1] CGColor];
                [cell.buShouYinBtn setUserInteractionEnabled:YES];
                [cell.buShouYinBtn setTitleColor:[UIColor colorWithRed:60.0f/255.0f green:60.0f/255.0f blue:60.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                
            }
        }
        if (indexPath.row == [exchangeNumArray count] - 1)
        {
            if (_PageIndex<=_TotalPage) {
                //  NSLog(@"###LOADING???");
                [self loadExchangeNextPage:_PageIndex];
            }
        }
        return cell;
    }
    if (tableView==_searchProductTableView) {
        static NSString * const  AccordByProductIdentifier = @"AccordByProductCellIdentifier";
        ServiceSearchProductTableViewCell  *cell=( ServiceSearchProductTableViewCell *)[tableView dequeueReusableCellWithIdentifier: AccordByProductIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"ServiceSearchProductTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame] ;
//        cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:250.0f/255.0f green:250.0f/255.0f blue:250.0f/255.0f alpha:1.0f];
        if (findProductImageArray.count>0) {
            //  NSLog(@"findProductURLArray====%@",findProductURLArray);
            NSString *leftUrlStr=[findProductImageArray objectAtIndex:indexPath.row];//[findProductURLArray objectAtIndex:indexPath.row];
            if (leftUrlStr.length>0) {
            [cell.productImageView setImageWithURL:[NSURL URLWithString:leftUrlStr]];
            }
            else
            {
                [cell.productImageView setImage:[UIImage imageNamed:@"zhanweitu_.png"]];
            }
        }
        if (findProductPriceArray.count>0) {
            [cell.productMarketPriceLabel setText:[NSString stringWithFormat:@"¥%@",[findProductPriceArray objectAtIndex:indexPath.row]]];
            [cell.productSalePriceLabel setText:[NSString stringWithFormat:@"¥%@",[findProductPriceArray objectAtIndex:indexPath.row]]];
            //[self resizeLabel:cell.productMarketPriceLabel];
           //  [self resizeLabel:cell.productSalePriceLabel];
            [Global resizeForLable:cell.productMarketPriceLabel WithText:cell.productMarketPriceLabel.text parentView:self.view];
            [Global resizeForLable:cell.productSalePriceLabel WithText:cell.productSalePriceLabel.text parentView:self.view];
            
            CGRect frame=cell.productSalePriceLabel.frame;
            frame.origin.x=590-cell.productSalePriceLabel.frame.size.width;
            cell.productSalePriceLabel.frame=frame;
           
        }
        if(findProductAddressArray.count>0 )
        {
            [cell.productAddressLabel setText:[findProductAddressArray objectAtIndex:indexPath.row]];
        }
        if(findProductWeightArray.count>0 )
        {
            [cell.productWeightLabel setText:[NSString stringWithFormat:@"%0.02fg",[[findProductWeightArray objectAtIndex:indexPath.row] floatValue]]];
           // [self resizeLabel:cell.productWeightLabel];
            [Global resizeForLable:cell.productWeightLabel WithText:cell.productWeightLabel.text parentView:self.view];
            CGRect frame=cell.productMarketPriceTagLabel.frame;
            frame.origin.x=cell.productWeightLabel.frame.origin.x+cell.productWeightLabel.frame.size.width+15;
            cell.productMarketPriceTagLabel.frame=frame;
            
            CGRect frame1=cell.productMarketPriceLabel.frame;
            frame1.origin.x=cell.productMarketPriceTagLabel.frame.origin.x+cell.productMarketPriceTagLabel.frame.size.width+2;
            cell.productMarketPriceLabel.frame=frame1;

        }
        
        if (findProductNameArray.count>0) {
           // [cell.productNameLabel setText:[findProductNameArray objectAtIndex:indexPath.row]];
            cell.productNameLabel.text=[NSString stringWithFormat:@"%@ %@",[findProductCodeArray objectAtIndex:indexPath.row],[findProductNameArray objectAtIndex:indexPath.row]];
        }
        if (indexPath.row == [findProductImageArray count] - 1)
        {
            if (_productPageIndex<=_productTotalPage) {
                //  NSLog(@"###LOADING???");
                [self loadProductNextPage:_productPageIndex];
            }
        }
        
        return cell;
    }
    else if (tableView==_resultGuideListTableView)
    {
        static NSString * const  GuideListIdentifier = @"GuideListCellIdentifier";
        GuideListTableViewCell *cell=( GuideListTableViewCell *)[tableView dequeueReusableCellWithIdentifier: GuideListIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"GuideListTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame] ;
//        cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:250.0f/255.0f green:250.0f/255.0f blue:250.0f/255.0f alpha:1.0f];
        if (guideNameArray.count>0) {
            cell.guideNameLabel.text=[guideNameArray objectAtIndex:indexPath.row];
        }
        return cell;
        
    }
    else if (tableView==_resultTableView)
    {
        static NSString * const  ResultTableViewCellIdentifier = @"ResultTableViewCellIdentifier";
        ResultTableViewCell *cell=( ResultTableViewCell *)[tableView dequeueReusableCellWithIdentifier: ResultTableViewCellIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"ResultTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame] ;
//        cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:250.0f/255.0f green:250.0f/255.0f blue:250.0f/255.0f alpha:1.0f];
        if (selectedProductImageArray.count>0) {
            if ([[selectedProductImageArray objectAtIndex:indexPath.row] length]>0) {
            
            [cell.resultProductImageView setImageWithURL:[NSURL URLWithString:[selectedProductImageArray objectAtIndex:indexPath.row]]];
            }
            else
            {
            [cell.resultProductImageView setImage:[UIImage imageNamed:@"zhanweitu_.png"]];
            }
        }
               if (selectedProductWeightArray.count>0) {
                   cell.resultProductWeightLabel.text=[NSString stringWithFormat:@"%0.02fg",[[selectedProductWeightArray objectAtIndex:indexPath.row] floatValue]];
                   cell.resultProductWeightLabel.numberOfLines = 0;
                   cell.resultProductWeightLabel.lineBreakMode = NSLineBreakByWordWrapping;
                   CGSize maximumLabelSize = CGSizeMake(1000, cell.resultProductWeightLabel.frame.size.height);
                   
                   CGSize expectSize = [cell.resultProductWeightLabel sizeThatFits:maximumLabelSize];
                   CGRect frame1 = CGRectMake(cell.resultProductWeightLabel.frame.origin.x, cell.resultProductWeightLabel.frame.origin.y,expectSize.width, cell.resultProductWeightLabel.frame.size.height );
                   cell.resultProductWeightLabel.frame=frame1;
                   
                   CGRect frame=cell.resultProductPriceLabel.frame;
                   frame.origin.x=cell.resultProductWeightLabel.frame.origin.x+cell.resultProductWeightLabel.frame.size.width+15;
                   cell.resultProductPriceLabel.frame=frame;

        }
        if (selectedProductPriceArray.count>0) {
            float AvgPrice=[[selectedProductPriceArray objectAtIndex:indexPath.row] floatValue];
            NSString *AvgPriceStr=[Global floatConvertPercentile:AvgPrice];
            cell.resultProductPriceLabel.text=[NSString stringWithFormat:@"¥%@",AvgPriceStr];
        }
        if (selectedProductNameArray.count>0) {
            cell.resultProductNameLabel.text=[NSString stringWithFormat:@"%@ %@",[selectedProductCodeArray objectAtIndex:indexPath.row],[selectedProductNameArray objectAtIndex:indexPath.row]];//[selectedProductNameArray objectAtIndex:indexPath.row];
        }
//        if (selectedStatusArray.count>0) {
//            cell.statusLabel.text=[selectedStatusArray objectAtIndex:indexPath.row];
//        }
        if ([cell.statusLabel.text isEqualToString:@"退"] ) {
            cell.resultProductDateLabel.hidden=NO;
            cell.resultProductDateLabel1.hidden=NO;
            if (selectedProductAddressArray.count>0) {
                cell.resultProductDateLabel.text=[selectedProductAddressArray objectAtIndex:indexPath.row];
            }
            [cell.statusLabel setBackgroundColor:[UIColor colorWithRed:196.0f/255.0f green:102.0f/255.0f blue:58.0f/255.0f alpha:1.0]];
        }
       else if ([cell.statusLabel.text isEqualToString:@"换"] ) {
            cell.resultProductDateLabel.hidden=YES;
            cell.resultProductDateLabel1.hidden=YES;
            [cell.statusLabel setBackgroundColor:[UIColor colorWithRed:201.0f/255.0f green:160.0f/255.0f blue:56.0f/255.0f alpha:1.0]];
        }

        cell.lineLabel.hidden=NO;
        if (indexPath.row==selectedProductCodeArray.count-1) {
            cell.lineLabel.hidden=YES;
        }
       
        return cell;
        
    }
    else if (tableView==_returnDetailTableView)
    {
        static NSString * const  ChangeTableViewCellIdentifier = @"ChangeTableViewCellIdentifier";
        OrderDetailTableViewCell *cell=( OrderDetailTableViewCell *)[tableView dequeueReusableCellWithIdentifier: ChangeTableViewCellIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"OrderDetailTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.stockAddressTagLabel.text=@"库存地点";
        //[self resizeLabel: cell.stockAddressTagLabel];
        cell.stockAddressTagLabel.numberOfLines = 0;
        cell.stockAddressTagLabel.lineBreakMode = NSLineBreakByWordWrapping;
        CGSize maximumLabelSize = CGSizeMake(1000, cell.stockAddressTagLabel.frame.size.height);
        
        CGSize expectSize = [cell.stockAddressTagLabel sizeThatFits:maximumLabelSize];
        CGRect frame1 = CGRectMake(cell.stockAddressTagLabel.frame.origin.x, cell.stockAddressTagLabel.frame.origin.y,expectSize.width, cell.stockAddressTagLabel.frame.size.height );
        cell.stockAddressTagLabel.frame=frame1;

        
        CGRect frameA= cell.stockAddressLabel.frame;
        frameA.origin.x=cell.stockAddressTagLabel.frame.origin.x+cell.stockAddressTagLabel.frame.size.width+5;
        cell.stockAddressLabel.frame=frameA;
//        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame] ;
//        cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:250.0f/255.0f green:250.0f/255.0f blue:250.0f/255.0f alpha:1.0f];
        if (returnDetailUrlArray.count>0) {
            
            if ([[returnDetailUrlArray objectAtIndex:indexPath.row] length]>0) {
            
            [cell.productImageView setImageWithURL:[NSURL URLWithString:[returnDetailUrlArray objectAtIndex:indexPath.row]]];
            }
            else
            {
            
            [cell.productImageView setImage:[UIImage imageNamed:@"zhanweitu_.png"]];
            }
        }
        if (returnDetailAddressArray.count>0) {
            cell.stockAddressLabel.text=[returnDetailAddressArray objectAtIndex:indexPath.row];
        }
        if (returnAttributesArray.count>0) {
            if ([returnAttributesArray objectAtIndex:indexPath.row]!=[NSNull null]) {
                cell.attributesLabel.text=[NSString stringWithFormat:@"%@",[returnAttributesArray objectAtIndex:indexPath.row]];
                
            }
            cell.attributesLabel.numberOfLines = 0;
            cell.attributesLabel.lineBreakMode = NSLineBreakByWordWrapping;
            CGSize maximumLabelSize = CGSizeMake(1000, cell.attributesLabel.frame.size.height);
            
            CGSize expectSize = [cell.attributesLabel sizeThatFits:maximumLabelSize];
            CGRect frame1 = CGRectMake(cell.attributesLabel.frame.origin.x, cell.attributesLabel.frame.origin.y,expectSize.width, cell.attributesLabel.frame.size.height );
            cell.attributesLabel.frame=frame1;
            
            // [self resizeLabel: cell.attributesLabel];
            
            CGRect frame= cell.weightTagLabel.frame;
            if ([[returnAttributesArray objectAtIndex:indexPath.row] length]>0) {
                
                frame.origin.x=cell.attributesLabel.frame.origin.x+cell.attributesLabel.frame.size.width+12;
            }
            else
            {
                frame.origin.x=cell.attributesLabel.frame.origin.x+cell.attributesLabel.frame.size.width;
            }
            cell.weightTagLabel.frame=frame;
            
            CGRect frame2= cell.weightLabel.frame;
            frame2.origin.x=cell.weightTagLabel.frame.origin.x+cell.weightTagLabel.frame.size.width+1;
            cell.weightLabel.frame=frame2;
            
        }
        


        if (returnDetailWeightArray.count>0) {
            cell.weightLabel.text=[NSString stringWithFormat:@"%0.02fg",[[returnDetailWeightArray objectAtIndex:indexPath.row] floatValue]];
           // [self resizeLabel:cell.resultProductWeightLabel];
            cell.weightLabel.numberOfLines = 0;
            cell.weightLabel.lineBreakMode = NSLineBreakByWordWrapping;
            CGSize maximumLabelSize = CGSizeMake(1000, cell.weightLabel.frame.size.height);
            
            CGSize expectSize = [cell.weightLabel sizeThatFits:maximumLabelSize];
            CGRect frame1 = CGRectMake(cell.weightLabel.frame.origin.x, cell.weightLabel.frame.origin.y,expectSize.width, cell.weightLabel.frame.size.height );
            cell.weightLabel.frame=frame1;

            CGRect frame=cell.priceLabel.frame;
            frame.origin.x=cell.weightLabel.frame.origin.x+cell.weightLabel.frame.size.width+15;
            cell.priceLabel.frame=frame;

        }
        if (returnDetailLinePriceArray.count>0) {
            float AvgPrice=[[returnDetailLinePriceArray objectAtIndex:indexPath.row] floatValue];
            NSString *AvgPriceStr=[Global floatConvertPercentile:AvgPrice];
            
          //  cell.productPriceLabel.text=[NSString stringWithFormat:@"¥%@",AvgPriceStr];
            cell.priceLabel.text=[NSString stringWithFormat:@"¥%@",AvgPriceStr];
        }
        if (returnDetailProductNameArray.count>0) {
            cell.productNameLabel.text=[NSString stringWithFormat:@"%@ %@",[returnDetailCodeArray objectAtIndex:indexPath.row],[returnDetailProductNameArray objectAtIndex:indexPath.row]];//[returnDetailProductNameArray objectAtIndex:indexPath.row];
            

        }
////        if (selectedStatusArray.count>0) {
//        cell.statusLabel.hidden=YES;
//     //   }
//        
//            cell.resultProductDateLabel.hidden=YES;
//            cell.resultProductDateLabel1.hidden=YES;
//        
        return cell;
        
    }
    
    return nil;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==_exchangeTableView) {
        exchangeCellTag=indexPath.row;
        [returnDetailUrlArray removeAllObjects];
        [returnDetailProductNameArray removeAllObjects];
        [returnDetailLinePriceArray removeAllObjects];
        [returnDetailWeightArray removeAllObjects];
        [returnAttributesArray removeAllObjects];
        [returnDetailCodeArray removeAllObjects];
        [returnDetailAddressArray removeAllObjects];

        [_returnDetailTableView reloadData];
        _relateNumLabel.text=@"";
        [self requestExchangeDetail:[exchangeNumArray objectAtIndex:indexPath.row]];
        [UIView animateWithDuration:0.5f animations:^
         {
             CGRect viewFrame=_exchangeDetailViewContainer.frame;
             viewFrame.origin.y=0;
             _exchangeDetailViewContainer.frame=viewFrame;
         }completion:^(BOOL finished) {
             
         }];

      
    }
    else if (tableView==_returnDetailTableView)
    {
        _isLoad=@"Y";
        if (commonProductDetailVC.view!=nil) {
            
            [commonProductDetailVC removeFromParentViewController];
            [commonProductDetailVC.view removeFromSuperview];
            
        }
        commonProductDetailVC=[[CommonProductDetailViewController alloc] init];
        commonProductDetailVC.delegate=self;
        commonProductDetailVC.codeStr=[returnDetailCodeArray objectAtIndex:indexPath.row];
        commonProductDetailVC.view.frame = CGRectMake(0,
                                                      0,
                                                      self.view.bounds.size.width,
                                                      self.view.bounds.size.height);
        
        [self addChildViewController:commonProductDetailVC];
        [self.view addSubview:commonProductDetailVC.view];

    }
    else if (tableView==_searchProductTableView)
    {
       [_searchProductTextField resignFirstResponder];
        if ([[findMemberCodeArray objectAtIndex:indexPath.row] isEqualToString:selectMemberCodeStr]||selectMemberCodeStr.length==0) {
        // if ([_statusLabel.text isEqualToString: @"退"]) {
            if ([[findMemberCodeArray objectAtIndex:indexPath.row] length]>0) {
                _memberNoteLabel.hidden=YES;
            }
            else
            {
                 _memberNoteLabel.hidden=NO;
            }
             _resultMemberNameAndPhoneLabel.hidden=NO;
             _resultSexImg.hidden=NO;
             _resultGradeTagLabel.hidden=NO;
             _resultGradeLabel.hidden=NO;
        _resultMemberNameAndPhoneLabel.text=[NSString stringWithFormat:@"(%@ %@)",[findMemberNameArray objectAtIndex:indexPath.row],[findMemberPhoneArray objectAtIndex:indexPath.row]];
        selectMemberCodeStr=[findMemberCodeArray objectAtIndex:indexPath.row];
       // [self resizeLabel:_resultMemberNameAndPhoneLabel];
        [Global resizeForLable:_resultMemberNameAndPhoneLabel WithText:_resultMemberNameAndPhoneLabel.text parentView:self.view];
        CGRect frame4=_resultSexImg.frame;
        frame4.origin.x=_resultMemberNameAndPhoneLabel.frame.origin.x+_resultMemberNameAndPhoneLabel.frame.size.width;
        _resultSexImg.frame=frame4;
        
        CGRect frame6=_resultGradeTagLabel.frame;
        frame6.origin.x=_resultSexImg.frame.origin.x+_resultSexImg.frame.size.width+10;
        _resultGradeTagLabel.frame=frame6;
        
        CGRect frame5=_resultGradeLabel.frame;
        frame5.origin.x=_resultGradeTagLabel.frame.origin.x+_resultGradeTagLabel.frame.size.width+3;
        _resultGradeLabel.frame=frame5;
        
        if ([[findMemberGradeArray objectAtIndex:indexPath.row] length]>0) {
            _resultGradeLabel.text=[findMemberGradeArray objectAtIndex:indexPath.row];
           // [self resizeLabel:_resultGradeLabel];
            [Global resizeForLable:_resultGradeLabel WithText:_resultGradeLabel.text parentView:self.view];
        }
        else
        {
            _resultGradeLabel.hidden=YES;
            _resultGradeTagLabel.hidden=YES;
        }
        
        
        if ([[findMemberSexArray objectAtIndex:indexPath.row]isEqualToString:@"男"]) {
            [_resultSexImg setImage:[UIImage imageNamed:@"nan_.png"]];
        }
        else if ([[findMemberSexArray objectAtIndex:indexPath.row]isEqualToString:@"女"])
        {
            [_resultSexImg setImage:[UIImage imageNamed:@"nv_.png"]];
        }
        else
        {
            _resultSexImg.hidden=YES;
        }

       //  }
        _resultNoteView.hidden=YES;

        searchProductCellTag=indexPath.row;
        CGRect viewFrame1=_addExchangeViewContainer.frame;
        viewFrame1.origin.y=0;
        _addExchangeViewContainer.frame=viewFrame1;
        
        CGRect frame=_addExchangeSearchView.frame;
        
        frame.origin.y=768;
        [_addExchangeSearchView setFrame:frame];
        
        CGRect frame0=_addExchangeSearchResultView.frame;
        
        frame0.origin.y=0;
        [_addExchangeSearchResultView setFrame:frame0];
        [UIView animateWithDuration:0.5 animations:^{
            UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
            [_resultGuideListArrowImage setImage:closeImage];

          
            
        } completion:^(BOOL finished){
            guideIsOpen=NO;
        }];
        if (![selectedProductCodeArray containsObject:[findProductCodeArray objectAtIndex:indexPath.row]]) {
            
        [selectedProductCodeArray insertObject:[findProductCodeArray objectAtIndex:indexPath.row] atIndex:0];
    
        NSString *urlStr=[findProductImageArray objectAtIndex:indexPath.row];
        [selectedProductImageArray insertObject:urlStr atIndex:0];
         //   if ([_statusLabel.text isEqualToString:@"退"]) {
      //  [selectedProductAddressArray addObject:[findProductAddressArray objectAtIndex:indexPath.row]];
            [selectedProductAddressArray insertObject:[findProductAddressArray objectAtIndex:indexPath.row] atIndex:0];
         //   }
        
        [selectedProductWeightArray insertObject:[NSString stringWithFormat:@"%0.02fg",[[findProductWeightArray objectAtIndex:indexPath.row] floatValue]] atIndex:0];
        [selectedProductPriceArray insertObject:[NSString stringWithFormat:@"%0.02f",[[findProductPriceArray objectAtIndex:indexPath.row] floatValue]] atIndex:0];
        [selectedProductNameArray insertObject:[findProductNameArray objectAtIndex:indexPath.row] atIndex:0];
       // [selectedStatusArray addObject:_statusLabel.text];
        }
        CGRect frame1=_resultTableView.frame;
        frame1.size.height=120*selectedProductCodeArray.count;
        _resultTableView.frame=frame1;
        
        [_resultTableView  reloadData];
        CGRect frame2=_resultView.frame;
        frame2.origin.y=_resultTableView.frame.origin.y+_resultTableView.frame.size.height;
        _resultView.frame=frame2;

        [_resultScrollview setContentSize:CGSizeMake(0, _resultView.frame.origin.y+ _resultView.frame.size.height+50)];
        [_resultScrollview setScrollEnabled:YES];
        float returnMoney=0;
        
        for (int i=0; i<selectedProductPriceArray.count; i++) {
           // if ([[selectedStatusArray objectAtIndex:i] isEqualToString:@"退"]) {
                returnMoney=returnMoney+[[selectedProductPriceArray objectAtIndex:i] floatValue];
           // }
      }
            
    _serviceMoneyTextField.text=[NSString stringWithFormat:@"%0.02f",returnMoney];
    _totalMoneyLabel.text= [NSString stringWithFormat:@"-%@",_serviceMoneyTextField.text];
        [self requestSearchInfo:[findProductCodeArray objectAtIndex:indexPath.row]];
        }
        else
        {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选择同一会员进行退货" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];

        }
    }
    else if (tableView==_resultGuideListTableView)
    {
        guideCodeStr=[guideCodeArray objectAtIndex:indexPath.row];
        searchGuideCellTag=indexPath.row;
        _resultGuideListViewContainer.hidden=YES;
        [UIView animateWithDuration:0.5 animations:^{
            
            UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
            [_resultGuideListArrowImage setImage:closeImage];
            CGRect frame=_resultGuideListViewContainer.frame;
            
            frame.size.height=1;
            [_resultGuideListViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            guideIsOpen=NO;
        }];
        _resultGuideNameLabel.text=[guideNameArray objectAtIndex:indexPath.row];
        [Global resizeForLable:_resultGuideNameLabel WithText:_resultGuideNameLabel.text parentView:self.view];
        CGRect frameK=_resultGuideNameLabel.frame;
        frameK.origin.x=_resultGuideListArrowImage.frame.origin.x-frameK.size.width-5;
        _resultGuideNameLabel.frame=frameK;

    }

}
-(void)commonProductDetailShopCartClick
{
    if ([self.delegate respondsToSelector:@selector(ReturnShopCtarClick)]) {
        
        [self.delegate ReturnShopCtarClick];
    }
    
}

-(void)requestSearchInfo:(NSString *)itemCode
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:itemCode forKey:@"ItemCode"];
        
        [HttpRequest requestData:@"Guide/GetItemExchangeOrder" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    
                      // NSLog(@"222=%@",severDataDict.dataDict);
                    NSMutableArray *dataLineArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    NSString *relateDateStr=@"";
                    NSString *relateNumStr=@"";
                    NSString *relateTotalStr=@"";
                    NSString *relateDecutibleStr=@"";
                    for (int i=0; i<dataLineArray.count; i++) {
                        relateDateStr=[[dataLineArray objectAtIndex:0] objectForKey:@"DocDate"];
                        relateNumStr=[[dataLineArray objectAtIndex:0] objectForKey:@"DocNum"];
                        relateTotalStr=[NSString stringWithFormat:@"%0.02f",[[[dataLineArray objectAtIndex:0] objectForKey:@"DocTotal"] floatValue]];
                        relateDecutibleStr=[NSString stringWithFormat:@"%0.02f",[[[dataLineArray objectAtIndex:0] objectForKey:@"Deduction"] floatValue]];
                    }
                   
                    if (relateNumStr.length>0) {
                        
                        _addRelateNoteLabel.hidden=YES;
                        _addRelateDateLabel.text=relateDateStr;
                        [Global resizeForLable:_addRelateDateLabel WithText:_addRelateDateLabel.text parentView:self.view];
                        CGRect frameA=_addRelateNumTagLabel.frame;
                        frameA.origin.x=_addRelateDateLabel.frame.origin.x+_addRelateDateLabel.frame.size.width+10;
                        _addRelateNumTagLabel.frame=frameA;
                        
                        CGRect frameB=_addRelateNumLabel.frame;
                        frameB.origin.x=_addRelateNumTagLabel.frame.origin.x+_addRelateNumTagLabel.frame.size.width+3;
                        _addRelateNumLabel.frame=frameB;

                        _addRelateNumLabel.text=relateNumStr;
                       // [self resizeLabel:_addRelateNumLabel];
                        [Global resizeForLable:_addRelateNumLabel WithText:_addRelateNumLabel.text parentView:self.view];
                       
                        _addRelateTotalLabel.text=relateTotalStr;
                       // [self resizeLabel:_addRelateTotalLabel];
                        [Global resizeForLable:_addRelateTotalLabel WithText:_addRelateTotalLabel.text parentView:self.view];
                        
                        _addRelateDecutibleLabel.text=relateDecutibleStr;
                      //  [self resizeLabel:_addRelateDecutibleLabel];
                         [Global resizeForLable:_addRelateDecutibleLabel WithText:_addRelateDecutibleLabel.text parentView:self.view];
                        
                        CGRect frameN=_addRelateTotalTagLabel.frame;
                        frameN.origin.x=_addRelateNumLabel.frame.origin.x+_addRelateNumLabel.frame.size.width+12;
                        _addRelateTotalTagLabel.frame=frameN;
                        
                        CGRect frameM=_addRelateTotalLabel.frame;
                        frameM.origin.x=_addRelateTotalTagLabel.frame.origin.x+_addRelateTotalTagLabel.frame.size.width+3;
                        _addRelateTotalLabel.frame=frameM;
                        
                        CGRect frameD=_addRelateDecutibleTagLabel.frame;
                        frameD.origin.x=_addRelateTotalLabel.frame.origin.x+_addRelateTotalLabel.frame.size.width+12;
                        _addRelateDecutibleTagLabel.frame=frameD;
                        
                        CGRect frameE=_addRelateDecutibleLabel.frame;
                        frameE.origin.x=_addRelateDecutibleTagLabel.frame.origin.x+_addRelateDecutibleTagLabel.frame.size.width+3;
                        _addRelateDecutibleLabel.frame=frameE;
                        
                    }
                    else
                    {
                        _addRelateNoteLabel.hidden=NO;
                    }

                    
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        [Global loginViewController:self noteStr:requestResultStr];
                        //    [Global loginViewController:self];
                    }
                    
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }

}
-(void)requestExchangeDetail:(NSString *)codeStr
{
//    _relateNumLabel.text=@"";
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:codeStr forKey:@"DocNum"];
        [HttpRequest requestData:@"Guide/ExchangeDetail" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    
                 //   NSLog(@"222=%@",severDataDict.dataDict);
                    NSString *relateDateStr=[severDataDict.dataDict objectForKey:@"RelationDate"];
                     NSString *relateNumStr=[severDataDict.dataDict objectForKey:@"OrderNum"];
                    if (relateNumStr.length>0) {
                        
                        _relateNoteLabel.hidden=YES;
                    _relateDateLabel.text=relateDateStr;
                    [Global resizeForLable:_relateDateLabel WithText:_relateDateLabel.text parentView:_exchangeDetailScrollview];
                        
                    CGRect frameA=_relateNumTagLabel.frame;
                    frameA.origin.x=_relateDateLabel.frame.origin.x+_relateDateLabel.frame.size.width+10;
                    _relateNumTagLabel.frame=frameA;
                        
                    CGRect frameB=_relateNumLabel.frame;
                    frameB.origin.x=_relateNumTagLabel.frame.origin.x+_relateNumTagLabel.frame.size.width+2;
                    _relateNumLabel.frame=frameB;

                   
                    _relateNumLabel.text=relateNumStr;
                    [Global resizeForLable:_relateNumLabel WithText:_relateNumLabel.text parentView:self.view];
                  //  [self resizeLabel:_relateNumLabel];
                    NSString *relateTotalStr=[Global floatConvertPercentile:[[severDataDict.dataDict objectForKey:@"OrderDocTotal"] floatValue]];
                    _relateTotalLabel.text=relateTotalStr;
                     //   [self resizeLabel:_relateTotalLabel];
                    [Global resizeForLable:_relateTotalLabel WithText:_relateTotalLabel.text parentView:self.view];
                    NSString *relateDecutibleStr=[Global floatConvertPercentile:[[severDataDict.dataDict objectForKey:@"Deduction"] floatValue]];
                    _relateDecutibleLabel.text=relateDecutibleStr;
                      //  [self resizeLabel:_relateDecutibleLabel];
                     [Global resizeForLable:_relateDecutibleLabel WithText:_relateDecutibleLabel.text parentView:self.view];
                        CGRect frameN=_relateTotalTagLabel.frame;
                        frameN.origin.x=_relateNumLabel.frame.origin.x+_relateNumLabel.frame.size.width+12;
                        _relateTotalTagLabel.frame=frameN;
                        
                        CGRect frameM=_relateTotalLabel.frame;
                        frameM.origin.x=_relateTotalTagLabel.frame.origin.x+_relateTotalTagLabel.frame.size.width+3;
                        _relateTotalLabel.frame=frameM;
                        
                        CGRect frameD=_relateDecutibleTagLabel.frame;
                        frameD.origin.x=_relateTotalLabel.frame.origin.x+_relateTotalLabel.frame.size.width+12;
                        _relateDecutibleTagLabel.frame=frameD;
                        
                        CGRect frameE=_relateDecutibleLabel.frame;
                        frameE.origin.x=_relateDecutibleTagLabel.frame.origin.x+_relateDecutibleTagLabel.frame.size.width+3;
                        _relateDecutibleLabel.frame=frameE;

                    }
                    else
                    {
                         _relateNoteLabel.hidden=NO;
                    }

                    
                    _exchangeNumLabel.text=[severDataDict.dataDict objectForKey:@"DocNum"];
                   // [self resizeLabel:_exchangeNumLabel];
                     [Global resizeForLable:_exchangeNumLabel WithText:_exchangeNumLabel.text parentView:self.view];
                    CGRect frame8=_exchangeStatusLabel.frame;
                    frame8.origin.x=_exchangeNumLabel.frame.origin.x+_exchangeNumLabel.frame.size.width;
                    _exchangeStatusLabel.frame=frame8;
                   // _exchangeReasonLabel.text=[severDataDict.dataDict objectForKey:@"Reasons"];
                    NSString *statusStr=[severDataDict.dataDict objectForKey:@"DocStatus"];
                    _exchangeStatusLabel.text=[NSString stringWithFormat:@"【%@】",statusStr];
                  //  [self resizeLabel:_exchangeStatusLabel];
                     [Global resizeForLable:_exchangeStatusLabel WithText:_exchangeStatusLabel.text parentView:self.view];
                    if ([statusStr isEqualToString:@"已结算"]) {
                        [_exchangeStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                             }
                    else
                    {
                        [_exchangeStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                        //  [cell.returnStatusLabel setUserInteractionEnabled:YES];
                        
                        
                    }

                    NSString *reasonStr=[severDataDict.dataDict objectForKey:@"Reasons"];
                    _exchangeReasonLabel.text=[NSString stringWithFormat:@"【%@】",reasonStr];
                    
                    if ([reasonStr isEqualToString:@"质量问题"]) {
                        //  cell.returnStatusLabel.layer.borderColor=[[UIColor colorWithRed:144.0f/255.0f green:185.0f/255.0f blue:109.0f/255.0f alpha:1] CGColor];
                        //  [cell.confirmArrivalBtn.];
                        
                        [_exchangeReasonLabel setTextColor:[UIColor colorWithRed:0xCC/255.0f green:0x66/255.0f blue:0x00/255.0f alpha:1.0f] ];
                        //[cell.confirmArrivalBtn setTintColor:];
                        
                    }
                    else if ([reasonStr isEqualToString:@"不合适"])
                    {
                        [_exchangeReasonLabel  setTextColor:[UIColor colorWithRed:0xD2/255.0f green:0xAB/255.0f blue:0x39/255.0f alpha:1.0f] ];
                        //  [cell.returnStatusLabel setUserInteractionEnabled:YES];
                        
                        
                    }
                    else
                    {
                       [_exchangeReasonLabel  setTextColor:[UIColor colorWithRed:40.0f/255.0f green:40.0f/255.0f blue:40.0f/255.0f alpha:1.0f] ];
                    }
                   [Global resizeForLable:_exchangeReasonLabel WithText:_exchangeReasonLabel.text parentView:self.view];
                   // [self resizeLabel:_exchangeReasonLabel];
                    CGRect frame11=_exchangeReasonLabel.frame;
                    frame11.origin.x=_exchangeStatusLabel.frame.origin.x+_exchangeStatusLabel.frame.size.width;
                    _exchangeReasonLabel.frame=frame11;
                    
                   
                    if ([severDataDict.dataDict objectForKey:@"MemberName"]==[NSNull null]||[[severDataDict.dataDict objectForKey:@"MemberName"] length]==0) {
                        _memberNameLabel.text=@"未填写";
                    }
                    else
                    {
                    _memberNameLabel.text=[severDataDict.dataDict objectForKey:@"MemberName"];
                    }
                   // [self resizeLabel:_memberNameLabel];
                     [Global resizeForLable:_memberNameLabel WithText:_memberNameLabel.text parentView:self.view];
                    _guideNameLabel.text=[severDataDict.dataDict objectForKey:@"GuideName"];
                   // [self resizeLabel:_guideNameLabel];
                     [Global resizeForLable:_guideNameLabel WithText:_guideNameLabel.text parentView:self.view];
                    _storeNameLabel.text=[severDataDict.dataDict objectForKey:@"StoreName"];
                    CGRect frame=_guideNameTagLabel.frame;
                    frame.origin.x=_memberNameLabel.frame.origin.x+_memberNameLabel.frame.size.width+15;
                    _guideNameTagLabel.frame=frame;
                    
                    CGRect frame7=_guideNameLabel.frame;
                    frame7.origin.x=_guideNameTagLabel.frame.origin.x+_guideNameTagLabel.frame.size.width+3;
                    _guideNameLabel.frame=frame7;
                    
                    CGRect frame5=_storeNameTagLabel.frame;
                    frame5.origin.x=_guideNameLabel.frame.origin.x+_guideNameLabel.frame.size.width+15;
                    _storeNameTagLabel.frame=frame5;
                    
                    CGRect frame6=_storeNameLabel.frame;
                    frame6.origin.x=_storeNameTagLabel.frame.origin.x+_storeNameTagLabel.frame.size.width+3;
                    _storeNameLabel.frame=frame6;

                    _remarkTextView.text=[severDataDict.dataDict objectForKey:@"Remark"];
                   // [Global resizeTextView:_remarkTextView contentStr:_remarkTextView.text];
                    CGFloat height=  [Global heightForTextView:_remarkTextView WithText:_remarkTextView.text];
                    
                    CGRect frameA=_remarkTextView.frame;
                    frameA.size.height=height;
                    _remarkTextView.frame=frameA;
                    
                    CGRect frameD=_lastView.frame;
                    frameD.size.height=_remarkTextView.frame.origin.y+_remarkTextView.frame.size.height+10;
                    _lastView.frame=frameD;
                    
                    _dateLabel.text=[severDataDict.dataDict objectForKey:@"DocDate"];
                    NSString *returnNumStr=[NSString stringWithFormat:@"%d",[[severDataDict.dataDict objectForKey:@"NumberD"] intValue]];
                  //  NSString *changeNumStr=[NSString stringWithFormat:@"%d",[[severDataDict.dataDict objectForKey:@"NumberE"] intValue]];
                    NSString *returnWeightStr=[NSString stringWithFormat:@"%0.02f",[[severDataDict.dataDict objectForKey:@"GramTotalD"] floatValue]];
                    // NSString *changeWeightStr=[NSString stringWithFormat:@"%0.02f",[[severDataDict.dataDict objectForKey:@"GramTotalE"] floatValue]];
                    _returnNumAndWeightLabel.text=[NSString stringWithFormat:@"(共%@件,%@g)",returnNumStr,returnWeightStr];
                   // _changeNumAndWeightLabel.text=[NSString stringWithFormat:@"(共%@件,%@g)",changeNumStr,changeWeightStr];
                    NSMutableArray *returnDataLineArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    float returnMonney=0;
                    for (int i=0; i<returnDataLineArray.count; i++) {
                        [returnDetailUrlArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"ImageUrl"]];
                        [returnDetailProductNameArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"ItemName"]];
                         [returnDetailCodeArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"ItemCode"]];
                        
                        NSString *lineTotalStr=[NSString stringWithFormat:@"%0.02f",[[[returnDataLineArray objectAtIndex:i] objectForKey:@"LineTotal"] floatValue]];
                        [returnDetailLinePriceArray addObject:lineTotalStr];
                        returnMonney=returnMonney+[lineTotalStr floatValue];
                         NSString *weightStr=[NSString stringWithFormat:@"%0.02f",[[[returnDataLineArray objectAtIndex:i] objectForKey:@"Gram"] floatValue]];
                        [returnDetailWeightArray addObject:weightStr];
                        [returnDetailAddressArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"WhsName"]];
                        [returnAttributesArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"Attributes"]];
                      
                    }

                    
                    float AvgPrice=[[exchangePriceArray objectAtIndex:exchangeCellTag] floatValue];
                    NSString *AvgPriceStr=[Global floatConvertPercentile:AvgPrice];
                    _differencePriceLabel.text=[NSString stringWithFormat:@"¥%@",AvgPriceStr];
                  //  [self resizeLabel: _differencePriceLabel];
                    [Global resizeForLable:_differencePriceLabel WithText:_differencePriceLabel.text parentView:self.view];
                    
                    CGRect difRect=_differencePriceLabel.frame;
                    difRect.origin.x=596-difRect.size.width;
                    _differencePriceLabel.frame=difRect;
                    
                    
                    CGRect difTagRect=_differencePriceTagLabel.frame;
                    difTagRect.origin.x=596-difRect.size.width-difTagRect.size.width-8;
                    _differencePriceTagLabel.frame=difTagRect;
                 //   [_changeDetailTableView reloadData];
                    [_returnDetailTableView reloadData];
                    CGRect frame1=_returnDetailTableView.frame;
                    frame1.size.height=120*returnDetailUrlArray.count;
                    _returnDetailTableView.frame=frame1;
                    
                    
//                    CGRect frame3=_changeDetailTableView.frame;
//                    frame3.size.height=120*changeDetailUrlArray.count;
//                    frame3.origin.y=_changeTitleView.frame.origin.y+_changeTitleView.frame.size.height;
//                    _changeDetailTableView.frame=frame3;
                    
                    CGRect frame4=_lastView.frame;
                  
                    frame4.origin.y=_returnDetailTableView.frame.origin.y+_returnDetailTableView.frame.size.height;
                    _lastView.frame=frame4;

                    [_exchangeDetailScrollview setContentSize:CGSizeMake(0, _lastView.frame.origin.y+ _lastView.frame.size.height)];
                    [_exchangeDetailScrollview setScrollEnabled:YES];
                    
                   
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                     [Global loginViewController:self noteStr:requestResultStr];
                    //    [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }

}

- (void)textClick
{
    
    [_searchProductTextField becomeFirstResponder];
}
-(void)serviceMoneyTextFieldBeginInput
{
    [UIView animateWithDuration:0.3 animations:^{
        //        CGRect viewFrame=_resultScrollView.frame;
        //        viewFrame.origin.y=-(_resultView.frame.origin.y+_serviceMoneyTextField.frame.origin.y+_serviceMoneyTextField.frame.size.height-_resultScrollView.contentOffset.y+356-768);
        //        _resultScrollView.frame=viewFrame;
        //
        
        
        CGFloat offset=0.0;
        CGRect frameA=_resultView.frame;
        frameA.origin.y=768-([Global getKeyboardHeight]+_serviceMoneyTextField.frame.size.height+_serviceMoneyTextField.frame.origin.y);
        offset=frameA.origin.y-_resultView.frame.origin.y+_resultScrollview.contentOffset.y;
        
        CGRect viewFrame=_resultScrollview.frame;
        viewFrame.origin.y=offset;
        _resultScrollview.frame=viewFrame;
    } completion:^(BOOL finished){
        
    }];
    
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
 
   if (textField==_serviceMoneyTextField)
    {
        inputTextField=_serviceMoneyTextField;
        [self performSelector:@selector(serviceMoneyTextFieldBeginInput) withObject:nil afterDelay:0.1];
        
    }
    else if (textField==_resultTextField)
    {
         [self performSelector:@selector(textClick) withObject:nil afterDelay:0.1];
            CGRect viewFrame=_addExchangeViewContainer.frame;
        viewFrame.origin.y=0;
        _addExchangeViewContainer.frame=viewFrame;
        CGRect viewFrame0=_addExchangeSearchResultView.frame;
        viewFrame0.origin.y=0;
        _addExchangeSearchResultView.frame=viewFrame0;
       
//        [UIView animateWithDuration:0.5f animations:^
//         {
             CGRect viewFrame1=_addExchangeSearchView.frame;
             viewFrame1.origin.y=0;
             _addExchangeSearchView.frame=viewFrame1;
//         }completion:^(BOOL finished) {
//             
//         }];
        return NO;
    }
   
    return YES;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView==_resultTableView) {
        return YES;
    }
    return NO;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView==_resultTableView) {
        if (editingStyle == UITableViewCellEditingStyleDelete) {
            [selectedProductImageArray removeObjectAtIndex:indexPath.row];
            [selectedProductWeightArray removeObjectAtIndex:indexPath.row];
           
//            if ([[selectedStatusArray objectAtIndex:indexPath.row] isEqualToString:@"退"]) {
                [selectedProductAddressArray removeObjectAtIndex:indexPath.row];
//            }
//             [selectedStatusArray removeObjectAtIndex:indexPath.row];
            [selectedProductPriceArray removeObjectAtIndex:indexPath.row];
            [selectedProductNameArray removeObjectAtIndex:indexPath.row];
            [selectedProductCodeArray removeObjectAtIndex:indexPath.row];
            
           // [tableView reloadData];
             [_resultTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            CGRect frame1=_resultTableView.frame;
            frame1.size.height=120*selectedProductCodeArray.count;
            _resultTableView.frame=frame1;
            
            
            CGRect frame2=_resultView.frame;
            frame2.origin.y=_resultTableView.frame.origin.y+_resultTableView.frame.size.height;
            _resultView.frame=frame2;
            
//            
//            
//            if (_resultView.frame.origin.y+_resultView.frame.size.height>707) {
//                CGRect frame0=_resultLastView.frame;
//                frame0.origin.y=_resultView.frame.origin.y+_resultView.frame.size.height+10;
//                _resultLastView.frame=frame0;
//            }
            [_resultScrollview setContentSize:CGSizeMake(0, _resultView.frame.origin.y+ _resultView.frame.size.height+50)];
            [_resultScrollview setScrollEnabled:YES];
            
            float returnMoney=0;
          //  float changeMoney=0;
            for (int i=0; i<selectedProductPriceArray.count; i++) {
              //  if ([[selectedStatusArray objectAtIndex:i] isEqualToString:@"退"]) {
                    returnMoney=returnMoney+[[selectedProductPriceArray objectAtIndex:i] floatValue];
                //}
//                else  if ([[selectedStatusArray objectAtIndex:i] isEqualToString:@"换"]) {
//                    changeMoney=changeMoney+[[selectedProductPriceArray objectAtIndex:i] floatValue];
//                }
            }
//            _serviceMoneyTextField.text=[NSString stringWithFormat:@"%0.02f",changeMoney-returnMoney];
//            _totalMoneyLabel.text= _serviceMoneyTextField.text;
            
            _serviceMoneyTextField.text=[NSString stringWithFormat:@"%0.02f",returnMoney];
            _totalMoneyLabel.text= [NSString stringWithFormat:@"-%@",_serviceMoneyTextField.text];
            
            if (selectedProductCodeArray.count==0) {
                _addRelateNoteLabel.hidden=NO;
                _addRelateNumLabel.text=@"";
                _resultGradeLabel.hidden=YES;
                _resultGradeTagLabel.hidden=YES;
                _resultSexImg.hidden=YES;
                _resultMemberNameAndPhoneLabel.hidden=YES;
                _resultMemberNameAndPhoneLabel.text=@"";
                selectMemberCodeStr=@"";
                _memberNoteLabel.hidden=NO;
               
                for (int i=0; i<3; i++) {
                    UIImageView *img=(UIImageView *)[self.view viewWithTag:2000+i];
                    [img setImage:[UIImage imageNamed:@"0000.png"]];
                    
                }

                serviceTypeStr=@"";
                guideCodeStr=[Global getGuideCodeStr];
                _guideNameLabel.text=@"";
                _serviceMoneyTextField.text=@"";
                _resultGuideNameLabel.text=[Global getGuideNameStr];
                [Global resizeForLable:_resultGuideNameLabel WithText:_resultGuideNameLabel.text parentView:self.view];
                CGRect frameK=_resultGuideNameLabel.frame;
                frameK.origin.x=_resultGuideListArrowImage.frame.origin.x-frameK.size.width-5;
                _resultGuideNameLabel.frame=frameK;

                
                _serviceMoneyTextField
                .text=@"";
                
                CGRect frame3=_resultTableView.frame;
                frame3.size.height=120;
                _resultTableView.frame=frame3;
                
                CGRect frame2=_resultView.frame;
                frame2.origin.y=289;
                _resultView.frame=frame2;
                
                //    CGRect frame0=_resultLastView.frame;
                //    frame0.origin.y=707;
                //    _resultLastView.frame=frame0;
                
                [_resultScrollview setContentSize:CGSizeMake(0, _resultView.frame.origin.y+ _resultView.frame.size.height+50)];
                [_resultScrollview setScrollEnabled:YES];

               
                _searchProductTextField.text=@"";
                _searchTotalLabel.text=@"共有0个结果";
                _resultNoteView.hidden=NO;
                
                CGRect frame1=_resultTableView.frame;
                frame1.size.height=120 ;
                _resultTableView.frame=frame1;
                
            }


            
        }
    }
  
}
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
    return @"删除";
}


- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField==_serviceMoneyTextField)
    {
        [_resultScrollview setContentOffset:CGPointMake(0, 0)];
        [UIView animateWithDuration:0.3 animations:^{
            CGRect viewFrame=_addExchangeViewContainer.frame;
            viewFrame.origin.y=0;
            _addExchangeViewContainer.frame=viewFrame;
            
            CGRect viewFrameA=_resultScrollview.frame;
            viewFrameA.origin.y=0;
            _resultScrollview.frame=viewFrameA;
        } completion:^(BOOL finished){
            
        }];
        
    }
    
   

}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
      if(textField==_searchProductTextField)
    {
        [findProductWeightArray removeAllObjects];
        [findProductImageArray removeAllObjects];
        // NSMutableArray *findProductURLArray;
        [findProductCodeArray removeAllObjects];
        [findProductNameArray removeAllObjects];
        [findProductPriceArray removeAllObjects];
        [findProductDateArray removeAllObjects];
        [findMemberNameArray removeAllObjects];
        [findMemberPhoneArray removeAllObjects];
        [findMemberGradeArray removeAllObjects];
        [findMemberSexArray removeAllObjects];
        [findMemberCodeArray removeAllObjects];
        [findProductAddressArray removeAllObjects];
        _productPageIndex=0;
        [self loadProductNextPage:_productPageIndex];
        [_searchProductTextField resignFirstResponder];
    }
    if (textField==_serviceMoneyTextField)
    {
        [UIView animateWithDuration:0.3 animations:^{
            CGRect viewFrame=_addExchangeViewContainer.frame;
            viewFrame.origin.y=0;
            _addExchangeViewContainer.frame=viewFrame;
        } completion:^(BOOL finished){
            
        }];
        [_serviceMoneyTextField resignFirstResponder];
        
    }
    if (textField==_searchTextField) {
        [exchangeNumArray removeAllObjects];
        [exchangeTypeArray removeAllObjects];
        [exchangeWeightArray removeAllObjects];
        [exchangeNumberArray removeAllObjects];
        [exchangeStatusArray removeAllObjects];
        [exchangeProductNameArray removeAllObjects];
        [exchangeGuideNameArray removeAllObjects];
        [exchangeMemberNameArray removeAllObjects];
        [exchangePriceArray removeAllObjects];
        [exchangeDateArray removeAllObjects];
        [ exchangeReasonArray removeAllObjects];
        _PageIndex=0;
        [self loadExchangeNextPage:_PageIndex];
        [_searchTextField resignFirstResponder];
    }

    return YES;
}

- (void)textViewDidChange:(UITextView *)textView
{
    
    if (textView==_resultTextView) {
        if (textView.text.length == 0) {
            _resultTextViewImage.hidden=NO;
            _resultTextViewLabel.hidden=NO;
        }
        else
        {
            _resultTextViewImage.hidden=YES;
            _resultTextViewLabel.hidden=YES;
            
        }
        
    }
    
}
-(void)resultTextViewBeginInput
{
    
    [UIView animateWithDuration:0.3 animations:^{
        CGFloat offset=0.0;
        CGRect frameA=_resultView.frame;
        frameA.origin.y=768-([Global getKeyboardHeight]+_resultTextView.frame.size.height+_resultTextView.frame.origin.y);
        offset=frameA.origin.y-_resultView.frame.origin.y+_resultScrollview.contentOffset.y;
        
        CGRect viewFrame=_resultScrollview.frame;
        viewFrame.origin.y=offset;
        _resultScrollview.frame=viewFrame;
    } completion:^(BOOL finished){
        
    }];
    
    
  


}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    if (textView==_resultTextView) {
        [self performSelector:@selector(resultTextViewBeginInput) withObject:nil afterDelay:0.1];

      
    }
  
    
    return YES;
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
   
    
  if (textView==_resultTextView) {
      [_resultScrollview setContentOffset:CGPointMake(0, 0)];
        [UIView animateWithDuration:0.3 animations:^{
            CGRect viewFrame=_addExchangeViewContainer.frame;
            viewFrame.origin.y=0;
            _addExchangeViewContainer.frame=viewFrame;
            
            CGRect viewFrameA=_resultScrollview.frame;
            viewFrameA.origin.y=0;
            _resultScrollview.frame=viewFrameA;
        } completion:^(BOOL finished){
            
        }];
        
    }
    
}
-(IBAction)addExchangeScanBtnClick :(id)sender
{
    if (commonScanVC.view!=nil) {
        
        [commonScanVC removeFromParentViewController];
        [commonScanVC.view removeFromSuperview];
        
    }
    commonScanVC=[[CommonScanViewController alloc] init];
    commonScanVC.delegate=self;
    
    commonScanVC.view.frame = CGRectMake(0,
                                         0,
                                         self.view.bounds.size.width,
                                         self.view.bounds.size.height);
    
    [self addChildViewController:commonScanVC];
    [self.view addSubview:commonScanVC.view];
    
}
-(void)CommonScanResult:(NSString *)codeStr
{
    //NSLog(@"codeStr=====%@",codeStr);
    if (commonScanVC.view!=nil) {
        //   NSLog(@"dddddddd");
        [commonScanVC removeFromParentViewController];
        [commonScanVC.view removeFromSuperview];
        
    }
    [self findScan:codeStr];
    
}
-(void)findScan:(NSString *)keyWord
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:keyWord forKey:@"KeyWord"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:1];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:0];
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
        [params setObject:@"Exchange1" forKey:@"BType"];
        [HttpRequest requestData:@"Product/GetPItemList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    _searchNoteView.hidden=YES;
                    // NSLog(@"findProductList/////=%@",severDataDict.dataDict);
                    
                    NSMutableArray  *findmProducts=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    if (findmProducts.count>0) {
                        
                        
                        NSString *memberCodeString=[[findmProducts objectAtIndex:0] objectForKey:@"MemberCode"];
                        if ([memberCodeString isEqualToString:selectMemberCodeStr]||selectMemberCodeStr.length==0) {
                            selectMemberCodeStr=[[findmProducts objectAtIndex:0] objectForKey:@"MemberCode"];
                            
                            _resultMemberNameAndPhoneLabel.hidden=NO;
                            _resultSexImg.hidden=NO;
                            _resultGradeTagLabel.hidden=NO;
                            _resultGradeLabel.hidden=NO;
                            _resultNoteView.hidden=YES;
                            
                            _resultMemberNameAndPhoneLabel.text=[NSString stringWithFormat:@"(%@ %@)",[[findmProducts objectAtIndex:0] objectForKey:@"MemberName"],[[findmProducts objectAtIndex:0] objectForKey:@"Phone"]];
                            // [self resizeLabel:_resultMemberNameAndPhoneLabel];
                            [Global resizeForLable:_resultMemberNameAndPhoneLabel WithText:_resultMemberNameAndPhoneLabel.text parentView:self.view];
                            if([memberCodeString length]>0)
                            {
                                _memberNoteLabel.hidden=YES;
                                
                            }
                            else
                            {
                                _memberNoteLabel.hidden=NO;
                            }
                            CGRect frame4=_resultSexImg.frame;
                            frame4.origin.x=_resultMemberNameAndPhoneLabel.frame.origin.x+_resultMemberNameAndPhoneLabel.frame.size.width;
                            _resultSexImg.frame=frame4;
                            
                            CGRect frame6=_resultGradeTagLabel.frame;
                            frame6.origin.x=_resultSexImg.frame.origin.x+_resultSexImg.frame.size.width+10;
                            _resultGradeTagLabel.frame=frame6;
                            
                            CGRect frame5=_resultGradeLabel.frame;
                            frame5.origin.x=_resultGradeTagLabel.frame.origin.x+_resultGradeTagLabel.frame.size.width+3;
                            _resultGradeLabel.frame=frame5;
                            
                            NSString *memberGradeStr=[[findmProducts objectAtIndex:0] objectForKey:@"Grade"];
                            if ([memberGradeStr length]>0) {
                                _resultGradeLabel.text=[[findmProducts objectAtIndex:0] objectForKey:@"Grade"];
                                // [self resizeLabel:_resultGradeLabel];
                                [Global resizeForLable:_resultGradeLabel WithText:_resultGradeLabel.text parentView:self.view];
                            }
                            else
                            {
                                _resultGradeLabel.hidden=YES;
                                _resultGradeTagLabel.hidden=YES;
                            }
                            
                            NSString *sexString=[[findmProducts objectAtIndex:0] objectForKey:@"Sex"];
                            if ([sexString isEqualToString:@"男"]) {
                                [_resultSexImg setImage:[UIImage imageNamed:@"nan_.png"]];
                            }
                            else if ([ sexString isEqualToString:@"女"])
                            {
                                [_resultSexImg setImage:[UIImage imageNamed:@"nv_.png"]];
                            }
                            else
                            {
                                _resultSexImg.hidden=YES;
                            }
                            
                            NSString *productCodeString=[[findmProducts objectAtIndex:0] objectForKey:@"ItemCode"];
                            if (![selectedProductCodeArray containsObject:productCodeString]) {
                                for (int i=0; i<findmProducts.count; i++) {
                                    [selectedProductImageArray insertObject:[[findmProducts objectAtIndex:i] objectForKey:@"ImageUrl"] atIndex:0];
                                    [selectedProductCodeArray insertObject:[[findmProducts objectAtIndex:i] objectForKey:@"ItemCode"] atIndex:0];
                                    [selectedProductNameArray insertObject:[[findmProducts objectAtIndex:i] objectForKey:@"ItemName"] atIndex:0];
                                    [selectedProductPriceArray insertObject:[[findmProducts objectAtIndex:i] objectForKey:@"Price"] atIndex:0];
                                    [selectedProductWeightArray insertObject:[[findmProducts objectAtIndex:i] objectForKey:@"Gram"] atIndex:0];
                                    [selectedProductAddressArray  insertObject:[[findmProducts objectAtIndex:i] objectForKey:@"MemberName"] atIndex:0];
                                    // [findProductDateArray  addObject:[[findmProducts objectAtIndex:i] objectForKey:@"DocDate"]];
                                }
                                CGRect frame1=_resultTableView.frame;
                                frame1.size.height=120*selectedProductCodeArray.count;
                                _resultTableView.frame=frame1;
                                
                                [_resultTableView  reloadData];
                                CGRect frame2=_resultView.frame;
                                frame2.origin.y=_resultTableView.frame.origin.y+_resultTableView.frame.size.height;
                                _resultView.frame=frame2;
                                [_resultScrollview setContentSize:CGSizeMake(0, _resultView.frame.origin.y+ _resultView.frame.size.height+50)];
                                [_resultScrollview setScrollEnabled:YES];
                                float returnMoney=0;
                                
                                for (int i=0; i<selectedProductPriceArray.count; i++) {
                                    // if ([[selectedStatusArray objectAtIndex:i] isEqualToString:@"退"]) {
                                    returnMoney=returnMoney+[[selectedProductPriceArray objectAtIndex:i] floatValue];
                                    // }
                                }
                                
                                _serviceMoneyTextField.text=[NSString stringWithFormat:@"%0.02f",returnMoney];
                                _totalMoneyLabel.text= [NSString stringWithFormat:@"-%@",_serviceMoneyTextField.text];
                                [self requestSearchInfo:[[findmProducts objectAtIndex:0] objectForKey:@"ItemCode"]];
                            }
                        }
                        else
                        {
                            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选择同一会员进行退货" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
                            [alert show];
                            
                        }
                    }
                    else
                    {
                        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"未找到该产品的信息" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
                        [alert show];
                    }
                    
                    //   [_searchProductTableView reloadData];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        
                        [Global loginViewController:self noteStr:requestResultStr];
                        //   [Global loginViewController:self];
                    }
                    
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}



-(void) loadProductNextPage:(NSUInteger)oldPageNum {
    if(oldPageNum!=0 && _productTotalCount<=findProductImageArray.count)
        return;
    if(oldPageNum == 0){
        [findProductImageArray removeAllObjects];
        [_searchProductTableView reloadData];
    }
    _productPageIndex=oldPageNum+1;
    // [self requestSeriesData:_productPageIndex pageSize:7];
    [self findProductList:_searchProductTextField.text pageIndex:_productPageIndex pageSize:6];
    
}
-(void)findProductList:(NSString *)keyWord pageIndex:(NSUInteger)pageIndex pageSize:(NSUInteger)pageSize
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:keyWord forKey:@"KeyWord"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:pageSize];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:pageIndex];
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
        [params setObject:typeStr forKey:@"BType"];
        [HttpRequest requestData:@"Product/GetPItemList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    _searchNoteView.hidden=YES;
                  //   NSLog(@"findProductList/////=%@",severDataDict.dataDict);
                    _productTotalCount=[[severDataDict.dataDict objectForKey:@"TotalCount"] integerValue];
                    _searchTotalLabel.text=[NSString stringWithFormat:@"共有%lu个结果",(unsigned long)_productTotalCount];
                    if (_productTotalCount%6!=0) {
                        _productTotalPage=_productTotalCount/6+1;
                    }
                    else if (_productTotalCount%6==0)
                    {
                        _productTotalPage=_productTotalCount/6;
                    }
                  NSMutableArray *findmProducts=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    for (int i=0; i<findmProducts.count; i++) {
                        [findProductImageArray addObject:[[findmProducts objectAtIndex:i] objectForKey:@"ImageUrl"]];
                        [findProductCodeArray addObject:[[findmProducts objectAtIndex:i] objectForKey:@"ItemCode"]];
                        [findProductNameArray addObject:[[findmProducts objectAtIndex:i] objectForKey:@"ItemName"]];
                        [findProductPriceArray addObject:[[findmProducts objectAtIndex:i] objectForKey:@"Price"]];
                        [findProductWeightArray addObject:[[findmProducts objectAtIndex:i] objectForKey:@"Gram"]];
                       // if ([_statusLabel.text isEqualToString: @"退"]) {
                      
                        [findMemberGradeArray  addObject:[[findmProducts objectAtIndex:i] objectForKey:@"Grade"]];
                        [findMemberSexArray  addObject:[[findmProducts objectAtIndex:i] objectForKey:@"Sex"]];
                        [findMemberNameArray addObject:[[findmProducts objectAtIndex:i] objectForKey:@"MemberName"]];
                        [findMemberPhoneArray addObject:[[findmProducts objectAtIndex:i] objectForKey:@"Phone"]];
                        [findMemberCodeArray addObject:[[findmProducts objectAtIndex:i] objectForKey:@"MemberCode"]];
                      //  }

                        [findProductAddressArray  addObject:[[findmProducts objectAtIndex:i] objectForKey:@"MemberName"]];
                      //  if ([_statusLabel.text isEqualToString: @"退"] ) {
                            [findProductDateArray  addObject:[[findmProducts objectAtIndex:i] objectForKey:@"DocDate"]];
                      //  }
                        
                    }
                    //                    for (int j=0; j <findProductImageArray.count; j++) {
                    //                        [findProductURLArray addObject:[[findProductImageArray objectAtIndex:j] objectForKey:@"ImageUrl"]];
                    //                    }
                    
                    //  NSLog(@"IMAGGGGGGG===%@",findProductImageArray);
                    //    NSLog(@"URLLLLLLL===%@",findProductURLArray);
                    [_searchProductTableView reloadData];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                    [Global loginViewController:self noteStr:requestResultStr];
                     //   [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}
-(void)serviceTypeClick:(UIButton *)button
{
    
    for (int i=0; i<3; i++) {
        UIImageView *img=(UIImageView *)[self.view viewWithTag:2000+i];
        [img setImage:[UIImage imageNamed:@"0000.png"]];
        
    }
    if(button.tag==1000)
    {
        serviceTypeStr=@"A";
    }
    else if (button.tag==1001)
    {
        serviceTypeStr=@"B";
    }
    else if(button.tag==1002)
    {
        serviceTypeStr=@"O";
    }
    UIImageView *img=(UIImageView *)[self.view viewWithTag:1000+button.tag];
    [img setImage:[UIImage imageNamed:@"1111.png"] ];
    
    
}
-(IBAction)submitServiceClick:(id)sender
{
    if (guideCodeStr.length>0&&serviceTypeStr.length>0&&selectedProductCodeArray.count>0) {
        
    
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableArray *mDocumentLine=[NSMutableArray array];
       //  NSMutableArray *mDocumentLine1=[NSMutableArray array];
        //        NSLog(@"findSkuAllCountArray===%@",findSkuAllCountArray);
         for (int i=0; i<selectedProductCodeArray.count; i++) {
            // if ([[selectedStatusArray objectAtIndex:i] isEqualToString:@"退"]) {
            NSString *codeStr =[selectedProductCodeArray objectAtIndex:i];
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        //    NSLog(@"codeContentssss==%@",codeContent);
        [dic setValue:codeStr forKey:@"ItemCode"];
        [mDocumentLine addObject:dic];
          //   }
//             else if ([[selectedStatusArray objectAtIndex:i] isEqualToString:@"换"])
//             {
//                
//                     NSString *codeStr =[selectedProductCodeArray objectAtIndex:i];
//                     NSMutableDictionary *dic = [NSMutableDictionary dictionary];
//                     //    NSLog(@"codeContentssss==%@",codeContent);
//                     [dic setValue:codeStr forKey:@"ItemCode"];
//                     [mDocumentLine1 addObject:dic];
//
//             }
         }
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:guideCodeStr forKey:@"GuideCode"];
        [params setObject:_resultTextView.text forKey:@"Remark"];
        [params setObject:_serviceMoneyTextField.text forKey:@"DocTotal"];
        [params setObject:serviceTypeStr forKey:@"Reasons"];
        [params setObject:mDocumentLine forKey:@"DataLine"];
      //  [params setObject:mDocumentLine1 forKey:@"DataLine1"];
        // NSLog(@"productStockPARAM===%@",params);
        [HttpRequest requestData:@"Guide/Exchange" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            // [Global hideProgressHUDInternal:self.view];
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    [Global showTextHudSub:requestResultStr view:self.view];
                  //  NSLog(@"111==%@",severDataDict.dataDict);
                    
                    [UIView animateWithDuration:0.5f animations:^
                     {
                         CGRect viewFrame1=_addExchangeViewContainer.frame;
                         viewFrame1.origin.y=768;
                         _addExchangeViewContainer.frame=viewFrame1;
                         CGRect viewFrame0=_addExchangeSearchView.frame;
                         viewFrame0.origin.y=768;
                         _addExchangeSearchView.frame=viewFrame0;

                         CGRect viewFrame=_addExchangeSearchResultView.frame;
                         viewFrame.origin.y=768;
                         _addExchangeSearchResultView.frame=viewFrame;
                     }completion:^(BOOL finished) {
                         
                     }];
                    guideCodeStr=@"";
                    _resultGuideNameLabel.text=@"";
                    for (int i=0; i<3; i++) {
                        UIImageView *img=(UIImageView *)[self.view viewWithTag:2000+i];
                        [img setImage:[UIImage imageNamed:@"0000.png"]];
                        
                    }
                   [selectedProductImageArray removeAllObjects];
                   [selectedProductAddressArray removeAllObjects];
                   [selectedProductWeightArray removeAllObjects];
                   [selectedProductPriceArray removeAllObjects];
                   [selectedProductNameArray removeAllObjects];
                    //[selectedStatusArray removeAllObjects];
                    [selectedProductCodeArray removeAllObjects];
                    [_resultTableView reloadData];
//                    if ([_serviceMoneyTextField.text floatValue]>0) {
//                        [UIView animateWithDuration:0.5f animations:^
//                         {
//                             CGRect viewFrame=_cashierViewContainer.frame;
//                             viewFrame.origin.y=0;
//                             _cashierViewContainer.frame=viewFrame;
//                         }completion:^(BOOL finished) {
//                             
//                         }];
//
//                   
//                    _cashierAmountLabel.text=[NSString stringWithFormat:@"%0.2f",[[severDataDict.dataDict objectForKey:@"Total"] floatValue]];
//                    _orderNumberLabel.text=[severDataDict.dataDict objectForKey:@"DocNum"];
//                        balanceAmountFloat=[[severDataDict.dataDict objectForKey:@"Total"] floatValue];
//                  //  _balancePayLabel.text=[NSString stringWithFormat:@"%0.2f",[[severDataDict.dataDict objectForKey:@"Total"] floatValue]];
//                        NSString *AvgPriceStr=[Global floatConvertPercentile:balanceAmountFloat];
//                        _balancePayLabel.text=AvgPriceStr;
//
//                    _memberAndPhoneLabel.text=_memberAndPhoneLabel.text=[NSString stringWithFormat:@"%@(%@)",[severDataDict.dataDict objectForKey:@"MemberName"],[severDataDict.dataDict objectForKey:@"Phone"]];
//                    _memberGradeLabel.text=[severDataDict.dataDict objectForKey:@"Grade"];
//                    guideCodeStr=[severDataDict.dataDict objectForKey:@"GuideCode"];
//                    _integralAvailabelLabel.text=[NSString stringWithFormat:@"¥%ld",(long)[[severDataDict.dataDict objectForKey:@"IntegralAmount"] integerValue]];
//                    _cashierGuideNameLabel.text=[severDataDict.dataDict objectForKey:@"GuideName"];
//                        [self resizeLabel1:_cashierGuideNameLabel];
//                        _integralTextField.text=@"";
//                        _deductibleTextField.text=@"";
//                        _cashierTextField.text=@"";
//                        _bankTextField.text=@"";
//                        _oldMeterialTextField.text=@"";
//                    }
                    [exchangeNumArray removeAllObjects];
                    [exchangeTypeArray removeAllObjects];
                    [exchangeWeightArray removeAllObjects];
                    [exchangeNumberArray removeAllObjects];
                    [exchangeStatusArray removeAllObjects];
                    [exchangeProductNameArray removeAllObjects];
                    [exchangeGuideNameArray removeAllObjects];
                    [exchangeMemberNameArray removeAllObjects];
                    [exchangePriceArray removeAllObjects];
                    [exchangeDateArray removeAllObjects];
                    [ exchangeReasonArray removeAllObjects];

                    _PageIndex=0;
                    [self loadExchangeNextPage:_PageIndex];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                    [Global loginViewController:self noteStr:requestResultStr];
                    //    [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    }
    else
    {
        if (guideCodeStr.length==0) {
        
        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选择导购" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
        }
        else if (serviceTypeStr.length==0)
        {
            
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选择退货原因" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];

        }
        else if (selectedProductCodeArray.count==0)
        {
            
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选择产品进行退换货" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
            
        }


    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
